Olli Graf
2 years ago
2 changed files with 70 additions and 10 deletions
@ -0,0 +1,37 @@ |
|||||
|
#! /usr/bin/python3 |
||||
|
import RPi.GPIO as GPIO |
||||
|
from time import sleep |
||||
|
import logging |
||||
|
|
||||
|
|
||||
|
__PIN__ = 16 # 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__': |
||||
|
GPIO.setwarnings(False) |
||||
|
# benutze Broadcom Pin Nummerierung |
||||
|
GPIO.setmode(GPIO.BCM) |
||||
|
|
||||
|
# Pin 16 als Input mit Pull-Up-Widerstand schalten. |
||||
|
logging.debug(f'konfiguriere Pin ${__PIN__} als Input.') |
||||
|
GPIO.setup(__PIN__, GPIO.IN, pull_up_down=GPIO.PUD_UP) |
||||
|
pressed = False |
||||
|
|
||||
|
logging.debug('Start der Schleife.') |
||||
|
try: |
||||
|
while True: |
||||
|
if not GPIO.input(__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