From d20813b4ff2777a1a77d1f27399fbb2822a8a951 Mon Sep 17 00:00:00 2001 From: Workantile Date: Wed, 22 Apr 2015 21:13:45 +0000 Subject: [PATCH] Add ON and OFF "macros" lowVoltage and highVoltage don't really tell us if the LEDs are on or off. Let's make this easier to understand. --- doors.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/doors.py b/doors.py index f4e18be..a2b8ddc 100755 --- a/doors.py +++ b/doors.py @@ -48,27 +48,30 @@ GPIO.setup(RED_LED, GPIO.OUT) GPIO.setup(GREEN_LED, GPIO.OUT) GPIO.setup(YELLOW_LED, GPIO.OUT) -#Be explicit with what we want -#lowVoltage of 0 is ground -lowVoltage = 0 -highVoltage = 1 -#Pull Enable Pin Low to make it readable -GPIO.output(DOOR_STRIKE, lowVoltage) +#Be explicit with what we want +OFF = 0 # Low voltage, ground +ON = 1 # High voltage + #When door is open def open_door(): print("Door is open"); - GPIO.output(GREEN_LED, highVoltage) - GPIO.output(RED_LED, lowVoltage) - GPIO.output(DOOR_STRIKE, highVoltage) + GPIO.output(DOOR_STRIKE, ON) + GPIO.output(RED_LED, OFF) + GPIO.output(GREEN_LED, ON) + GPIO.output(YELLOW_LED, OFF) #When door is closed and locked def close_door(): print("Door is closed"); - GPIO.output(DOOR_STRIKE, lowVoltage) - GPIO.output(GREEN_LED, lowVoltage) - GPIO.output(RED_LED, highVoltage) + GPIO.output(DOOR_STRIKE, OFF) + GPIO.output(RED_LED, ON) + GPIO.output(GREEN_LED, OFF) + GPIO.output(YELLOW_LED, OFF); + +close_door() +GPIO.output(YELLOW_LED, OFF) @@ -82,13 +85,11 @@ from urllib import request # Blocks for 5 seconds before resetting the door def verify_key(key): - GPIO.output(YELLOW_LED, highVoltage); + GPIO.output(YELLOW_LED, ON); with request.urlopen(SERVER + ("/%s" % key)) as f: if f.read().decode() == "OK": - GPIO.output(YELLOW_LED, lowVoltage); open_door() time.sleep(5) - GPIO.output(YELLOW_LED, lowVoltage); close_door() @@ -120,4 +121,5 @@ while True: try: read_rfid() except Exception(e): + door_close() print(e)