Wrote working manual mode script.
This commit is contained in:
74
manual/manual.py
Normal file
74
manual/manual.py
Normal 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()
|
||||
Reference in New Issue
Block a user