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
977 B
37 lines
977 B
#! /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)
|
|
|
|
logging.debug(f'konfiguriere Pin ${__PIN__} als Input.')
|
|
# Pin 16 als Input mit Pull-Up-Widerstand schalten.
|
|
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
|
|
|
|
|