From d12272d92c3ffa537227a063cd655343e87f884c Mon Sep 17 00:00:00 2001 From: Olli Graf Date: Fri, 27 Jun 2025 13:27:39 +0200 Subject: [PATCH] =?UTF-8?q?button5.py=20f=C3=BCr=20den=20Raspberry=20Pi=20?= =?UTF-8?q?5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- teil15/button.py | 2 +- teil15/button5.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 teil15/button5.py diff --git a/teil15/button.py b/teil15/button.py index 3211d20..93451ed 100755 --- a/teil15/button.py +++ b/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) diff --git a/teil15/button5.py b/teil15/button5.py new file mode 100755 index 0000000..2aad781 --- /dev/null +++ b/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 +