Created
January 19, 2018 09:14
-
-
Save simonjenny/416cedae410835927d1d6bcb7df5344d to your computer and use it in GitHub Desktop.
Fairytale Phone - Next Thing Co C.H.I.P Version
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 CHIP_IO.GPIO as GPIO | |
import math, sys, os | |
import subprocess | |
import socket | |
GPIO.setup("XIO-P7", GPIO.IN); | |
GPIO.setup("XIO-P6", GPIO.IN); | |
c=0 | |
last = 1 | |
def count(pin): | |
global c | |
c = c + 1 | |
GPIO.add_event_detect("XIO-P6", GPIO.BOTH) | |
while True: | |
try: | |
if GPIO.event_detected("XIO-P6"): | |
try: | |
player.kill() | |
except NameError: | |
pass | |
current = GPIO.input("XIO-P6") | |
if(last != current): | |
if(current == 0): | |
GPIO.add_event_detect("XIO-P7", GPIO.BOTH, callback=count, bouncetime=5) | |
else: | |
GPIO.remove_event_detect("XIO-P7") | |
number = math.floor(c/2) | |
print str(int(number)) | |
player = subprocess.Popen(["mpg123", "/media/" + str(int(number)) + ".mp3", "-q"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
c=0 | |
last = GPIO.input("XIO-P6") | |
except KeyboardInterrupt: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment