Created
January 31, 2015 20:36
-
-
Save lxfontes/0ea31b37f8b4aee86934 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
| 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