Last active
March 17, 2017 21:36
-
-
Save tomgross/939b3f0025296cffc238ecbd1ec57b83 to your computer and use it in GitHub Desktop.
Fairytale Phone
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/python | |
import RPi.GPIO as GPIO | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
c = 0 | |
last = 1 | |
def count(pin): | |
global c | |
c = c + 1 | |
GPIO.add_event_detect(18, GPIO.BOTH) | |
while True: | |
try: | |
if GPIO.event_detected(18): | |
current = GPIO.input(18) | |
if last != current: | |
if not current: | |
GPIO.add_event_detect(23, GPIO.BOTH, callback=count, bouncetime=5) | |
else: | |
GPIO.remove_event_detect(23) | |
number = c // 2 | |
c = 0 | |
last = GPIO.input(18) | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment