Skip to content

Instantly share code, notes, and snippets.

@shaag7967
Forked from simonjenny/phone.py
Last active October 7, 2018 12:34
Show Gist options
  • Save shaag7967/e2ebf332b080a6ae85776fe2a41c611a to your computer and use it in GitHub Desktop.
Save shaag7967/e2ebf332b080a6ae85776fe2a41c611a to your computer and use it in GitHub Desktop.
Fairytale Phone
#!/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