Created
June 6, 2019 17:21
-
-
Save command-tab/b66107234c722115d1349339e8588b8f to your computer and use it in GitHub Desktop.
RPi GPIO interrupt handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import RPi.GPIO as GPIO | |
import asyncio | |
import sys | |
PIN = 18 | |
def handle_edge(pin): | |
print('Edge callback') | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
try: | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) | |
GPIO.add_event_detect(PIN, GPIO.RISING, callback=handle_edge, bouncetime=500) | |
loop.run_forever() | |
except KeyboardInterrupt: | |
loop.close() | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment