From f53a5183bce73b15c3b091c1a5f1aa694769ff59 Mon Sep 17 00:00:00 2001 From: Shaun Setlock Date: Sat, 6 Nov 2021 19:06:43 -0400 Subject: [PATCH] Wrote working manual mode script. --- manual/manual.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 manual/manual.py diff --git a/manual/manual.py b/manual/manual.py new file mode 100644 index 0000000..1e64946 --- /dev/null +++ b/manual/manual.py @@ -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()