Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.