-
-
Save shaag7967/e2ebf332b080a6ae85776fe2a41c611a to your computer and use it in GitHub Desktop.
Fairytale Phone
This file contains 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 | |
IO_PIN_DIAL = 18 | |
IO_PIN_NUMBER = 23 | |
GPIO.setwarnings(False) | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(IO_PIN_DIAL, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
GPIO.setup(IO_PIN_NUMBER, GPIO.IN, pull_up_down=GPIO.PUD_UP) | |
counter=0 | |
last = 1 | |
def count(pin): | |
global counter | |
counter += 1 | |
GPIO.add_event_detect(IO_PIN_DIAL, GPIO.BOTH) | |
while True: | |
try: | |
if GPIO.event_detected(IO_PIN_DIAL): | |
current = GPIO.input(IO_PIN_DIAL) | |
if(last != current): | |
if(current == 0): | |
GPIO.add_event_detect(IO_PIN_NUMBER, GPIO.BOTH, callback=count, bouncetime=5) | |
else: | |
GPIO.remove_event_detect(IO_PIN_NUMBER) | |
number = (counter/2 + 1) % 10 | |
print number | |
counter=0 | |
last = GPIO.input(IO_PIN_DIAL) | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment