Skip to content

Instantly share code, notes, and snippets.

@command-tab
Created June 6, 2019 17:21
Show Gist options
  • Select an option

  • Save command-tab/b66107234c722115d1349339e8588b8f to your computer and use it in GitHub Desktop.

Select an option

Save command-tab/b66107234c722115d1349339e8588b8f to your computer and use it in GitHub Desktop.

Revisions

  1. @commandtab commandtab created this gist Jun 6, 2019.
    21 changes: 21 additions & 0 deletions edgetest.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/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()