Skip to content

Instantly share code, notes, and snippets.

@lxfontes
Created January 31, 2015 20:36
Show Gist options
  • Select an option

  • Save lxfontes/0ea31b37f8b4aee86934 to your computer and use it in GitHub Desktop.

Select an option

Save lxfontes/0ea31b37f8b4aee86934 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
import signal
import sys
def sig_handler(s,f):
print("Cleaning up")
GPIO.cleanup()
sys.exit(0)
signal.signal(signal.SIGINT, sig_handler)
pin = 13
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
times = 0
def pressed(ch):
global times
times += 1
print("Button Pressed %d times" % times)
GPIO.add_event_detect(pin, GPIO.RISING, callback=pressed, bouncetime=1000)
while True:
time.sleep(0.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment