Created
June 14, 2016 11:39
-
-
Save lurch/21005614c432fbf0fb69588d235c46fb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 python | |
import RPi.GPIO as GPIO | |
import sys | |
from signal import pause | |
def button_pressed(channel): | |
print("Button %d was pressed" % channel) | |
if len(sys.argv) < 2: | |
print("No port numbers were supplied!") | |
else: | |
GPIO.setmode(GPIO.BCM) | |
for arg in sys.argv[1:]: | |
port = int(arg) | |
print("Setting up BCM%d" % port) | |
GPIO.setup(port, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
GPIO.add_event_detect(port, GPIO.FALLING, callback=button_pressed, bouncetime=300) | |
try: | |
pause() | |
except KeyboardInterrupt: | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment