2 changed files with 38 additions and 1 deletions
@ -0,0 +1,37 @@ |
|||||
|
#! /usr/bin/python3 |
||||
|
import lgpio |
||||
|
from time import sleep |
||||
|
import logging |
||||
|
|
||||
|
# Programm zum Button Auslesen für den Raspberry Pi 5. |
||||
|
# Der wird vom RPi.GPIO nicht unterstützt, daher benutzen wir |
||||
|
# lgpio |
||||
|
|
||||
|
__PIN__ = 23 # GPIO Pin, für den Taster |
||||
|
__WAIT__ = 0.5 # Warten für 0,5 Sekunden |
||||
|
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.DEBUG) |
||||
|
|
||||
|
if __name__ =='__main__': |
||||
|
h = lgpio.gpiochip_open(0) |
||||
|
lgpio.gpio_claim_input(h, __PIN__ ) # GPIO23 |
||||
|
|
||||
|
logging.debug(f'konfiguriere Pin ${__PIN__} als Input.') |
||||
|
pressed = False |
||||
|
|
||||
|
logging.debug('Start der Schleife.') |
||||
|
try: |
||||
|
while True: |
||||
|
pressed = lgpio.gpio_read(h, __PIN__) |
||||
|
if not pressed: |
||||
|
logging.info('Button wurde gedrückt.') |
||||
|
pressed = True |
||||
|
else: |
||||
|
logging.debug('Button nicht gedrückt.') |
||||
|
pressed = False |
||||
|
|
||||
|
sleep(__WAIT__) |
||||
|
except KeyboardInterrupt: |
||||
|
logging.debug('Abbruch durch Benutzer.') |
||||
|
finally: |
||||
|
pass |
||||
|
|
Loading…
Reference in new issue