You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
978 B
37 lines
978 B
#! /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
|
|
|
|
|