Skip to content

Instantly share code, notes, and snippets.

@command-tab
Created June 6, 2019 17:21
Show Gist options
  • Save command-tab/b66107234c722115d1349339e8588b8f to your computer and use it in GitHub Desktop.
Save command-tab/b66107234c722115d1349339e8588b8f to your computer and use it in GitHub Desktop.
RPi GPIO interrupt handling
#!/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