Added button feature

master
Davide Bongiovanni 8 years ago
parent cf035f8b28
commit 353d306fc0

@ -1,7 +1,20 @@
import time
import json
import time, json
import RPi.GPIO as GPIO
if __name__ == '__main__':
pin_config = {}
with open('pin_config.json') as pin_config_stream:
pin_config = json.load(pin_config_stream)
if pin_config['mode'] == 'BOARD':
GPIO.setmode(GPIO.BOARD)
else:
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin_config['frigde_btn'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin_config['tools_btn'], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(pin_config['fridge_red_LED'], GPIO.OUT)
GPIO.setup(pin_config['fridge_grn_LED'], GPIO.OUT)
GPIO.setup(pin_config['tools_red_LED'], GPIO.OUT)
GPIO.setup(pin_config['tools_grn_LED'], GPIO.OUT)
while True:
cardID = raw_input("Enter card ID: ")
event = {}
@ -12,6 +25,36 @@ if __name__ == '__main__':
with open('cards/' + cardID + '.json') as card_data:
data = json.load(card_data)
event["name"] = data['name']
if data['secretTools']:
GPIO.output(pin_config['tools_grn_LED'], GPIO.HIGH)
else
GPIO.output(pin_config['tools_red_LED'], GPIO.HIGH)
if data['fridge']:
GPIO.output(pin_config['fridge_grn_LED'], GPIO.HIGH)
else
GPIO.output(pin_config['fridge_red_LED'], GPIO.HIGH)
timeout = time.time() + 5 # 5 seconds timeout
while wait:
if data['secretTools'] and GPIO.input(pin_config['tools_btn']) == 0:
wait = False
GPIO.output(pin_config['fridge_grn_LED'], GPIO.LOW)
GPIO.output(pin_config['tools_grn_LED'], GPIO.LOW)
GPIO.output(pin_config['fridge_red_LED'], GPIO.LOW)
GPIO.output(pin_config['tools_red_LED'], GPIO.LOW)
# Open tools
if data['fridge'] and GPIO.input(pin_config['fridge_btn']) == 0:
GPIO.output(pin_config['fridge_grn_LED'], GPIO.LOW)
GPIO.output(pin_config['tools_grn_LED'], GPIO.LOW)
GPIO.output(pin_config['fridge_red_LED'], GPIO.LOW)
GPIO.output(pin_config['tools_red_LED'], GPIO.LOW)
wait = False
# Open fridge
if time.time() > timeout:
GPIO.output(pin_config['fridge_grn_LED'], GPIO.LOW)
GPIO.output(pin_config['tools_grn_LED'], GPIO.LOW)
GPIO.output(pin_config['fridge_red_LED'], GPIO.LOW)
GPIO.output(pin_config['tools_red_LED'], GPIO.LOW)
wait = False
except:
print "Card not registered."
history = []

@ -0,0 +1,9 @@
{
"mode" : "BOARD",
"fridge_btn" : 16,
"tools_btn" : 18,
"fridge_red_LED" : 31,
"fridge_grn_LED" : 33,
"tools_red_LED" : 35,
"tools_grn_LED" : 37,
}
Loading…
Cancel
Save