Skip to content

Instantly share code, notes, and snippets.

@lurch
Created June 14, 2016 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lurch/21005614c432fbf0fb69588d235c46fb to your computer and use it in GitHub Desktop.
Save lurch/21005614c432fbf0fb69588d235c46fb to your computer and use it in GitHub Desktop.
#!/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