From 22032b7cc1ed1669a914c6177017c718ce9d1218 Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Fri, 21 Aug 2020 22:33:09 +0200 Subject: [PATCH] Key example --- .../python/examples/keys.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 RaspberryPi&JetsonNano/python/examples/keys.py diff --git a/RaspberryPi&JetsonNano/python/examples/keys.py b/RaspberryPi&JetsonNano/python/examples/keys.py new file mode 100644 index 0000000..bb9a8b3 --- /dev/null +++ b/RaspberryPi&JetsonNano/python/examples/keys.py @@ -0,0 +1,34 @@ +import RPi.GPIO as GPIO +import time + +GPIO.setmode(GPIO.BCM) + +key1 = 5 +key2 = 6 +key3 = 13 +key4 = 19 + +GPIO.setup(key1, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(key2, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(key3, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(key4, GPIO.IN, pull_up_down=GPIO.PUD_UP) + + +def interrupt(channel): + print("interrupt", channel) + + +GPIO.add_event_detect(key1, GPIO.FALLING, callback=interrupt, bouncetime=200) +GPIO.add_event_detect(key2, GPIO.FALLING, callback=interrupt, bouncetime=200) +GPIO.add_event_detect(key3, GPIO.FALLING, callback=interrupt, bouncetime=200) +GPIO.add_event_detect(key4, GPIO.FALLING, callback=interrupt, bouncetime=200) + +tic = 0 +try: + while True: + tic = tic + 1 + print("Tic %d" % tic) + time.sleep(1) +except KeyboardInterrupt: + GPIO.cleanup() + print("\nBye")