Skip to content

Instantly share code, notes, and snippets.

@tomgross
Forked from simonjenny/phone.py
Last active March 17, 2017 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomgross/939b3f0025296cffc238ecbd1ec57b83 to your computer and use it in GitHub Desktop.
Save tomgross/939b3f0025296cffc238ecbd1ec57b83 to your computer and use it in GitHub Desktop.
Fairytale Phone
#!/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