Skip to content

Instantly share code, notes, and snippets.

@tomgross
Forked from simonjenny/phone.py
Last active Mar 17, 2017
Embed
What would you like to do?
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