Archived
1
0

Wrote working manual mode script.

This commit is contained in:
Shaun Setlock
2021-11-06 19:06:43 -04:00
parent ac33a188ce
commit 16ea5fc721

74
manual/manual.py Normal file
View File

@@ -0,0 +1,74 @@
#! env/bin/python3
import RPi.GPIO as GPIO
import time
if __name__ == "__main__":
# Setup for Hardware
PB1_BCM = 4 # Green
PB2_BCM = 27 # Yellow
PB3_BCM = 13 # Blue
RELAY1_PIN = 26 # Water Pump
RELAY2_PIN = 20 # Unassigned
RELAY3_PIN = 21 # Lamp
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Setup the Inputs to use the internal pull-down.
GPIO.setup(PB1_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(PB2_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(PB3_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
# Setup the outputs to be initialized as OFF.
GPIO.setup(RELAY1_PIN, GPIO.OUT)
GPIO.output(RELAY1_PIN, False)
GPIO.setup(RELAY2_PIN, GPIO.OUT)
GPIO.output(RELAY2_PIN, False)
GPIO.setup(RELAY3_PIN, GPIO.OUT)
GPIO.output(RELAY3_PIN, False)
# Define alias variables for input devices.
green_button = False
yellow_button = False
blue_button = False
# Define state variables for each of the output devices.
pump_state = False
lamp_state = False
# Begin detected presses.
try:
while True:
# Detect inputs.
detect = False
green_button = GPIO.input(PB1_BCM)
yellow_button = GPIO.input(PB2_BCM)
blue_button = GPIO.input(PB3_BCM)
# Determine state.
if not detect and blue_button and pump_state:
pump_state = False
detect = True
if not detect and blue_button and not pump_state:
pump_state = True
detect = True
# Lamp
if not detect and yellow_button and lamp_state:
lamp_state = False
detect = True
if not detect and yellow_button and not lamp_state:
lamp_state = True
detect = True
# Write outputs.
if detect:
time.sleep(1.0)
GPIO.output(RELAY1_PIN, pump_state)
GPIO.output(RELAY3_PIN, lamp_state)
finally:
GPIO.cleanup()