Browse Source

button5.py für den Raspberry Pi 5

master teil15.1
Olli Graf 4 days ago
parent
commit
d12272d92c
  1. 2
      teil15/button.py
  2. 37
      teil15/button5.py

2
teil15/button.py

@ -4,7 +4,7 @@ from time import sleep
import logging
__PIN__ = 16 # GPIO Pin, für den Taster
__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)

37
teil15/button5.py

@ -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…
Cancel
Save