Last active
August 29, 2015 14:22
-
-
Save scottx611x/73abd19acbcf073f5e8d to your computer and use it in GitHub Desktop.
Raspberry Pi "Knocker"
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
import pifacedigitalio as pfio | |
import time,sys, threading | |
pifacedigital = pfio.PiFaceDigital() | |
pfio.init() | |
#Blink LED to let user know they can enter knock codes | |
def blink_LED(PIN): | |
while 1: | |
p = PIN | |
pfio.digital_write(p, 1) | |
time.sleep(.1) | |
pfio.digital_write(p, 0) | |
time.sleep(.1) | |
count = 0 | |
#Blue LED | |
PIN = 4 | |
#Blink Blue LED in a thread with its own timer | |
t = threading.Thread(target=blink_LED, args=(PIN,)) | |
t.start() | |
print "DEVICE READY\n" | |
print "Please knock ONCE to enter a new code: " | |
one_knock = 0 | |
while one_knock != 1: | |
#Check for action on the Piezo Pad | |
knock = pfio.digital_read(4,0) | |
if knock == 1: | |
one_knock = one_knock + 1 | |
print "KNOCK acknowledged!" | |
time.sleep(2) | |
print "Please enter your secret knock code: " | |
while True: | |
###################################################################### | |
# !!! INTERPRET KNOCK DATA !!! | |
###################################################################### | |
try: | |
#Check for action on the Piezo Pad | |
knock = pfio.digital_read(4,0) | |
#if a knock occurs.... | |
if knock == 1: | |
print "KNOCK%d" % count | |
count = count + 1 | |
#GREEN LED ON | |
pfio.digital_write(6, 1) | |
#RED LED OFF | |
pfio.digital_write(7, 0) | |
#Solenoid LOW | |
pfio.digital_write(5, 0) | |
time.sleep(.25) | |
else: | |
#RED LED ON | |
pfio.digital_write(7, 1) | |
#GREEN LED OFF | |
pfio.digital_write(6, 0) | |
#Solenoid HIGH | |
pfio.digital_write(5, 1) | |
except KeyboardInterrupt: | |
#General Cleanup | |
pfio.deinit() | |
sys.exit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment