Archived
1
0
This repository has been archived on 2025-04-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
garden/automatic/routine.py
2021-11-12 15:23:57 -05:00

70 lines
1.9 KiB
Python

#! env/bin/python3
import RPi.GPIO as GPIO
import time
from input import get_pin_input
from state_trans import check_state
from output import write_pin_output
if __name__ == "__main__":
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Pin Assignments
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
# 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.
GPIO.setup(RELAY1_PIN, GPIO.OUT)
GPIO.setup(RELAY2_PIN, GPIO.OUT)
GPIO.setup(RELAY3_PIN, GPIO.OUT)
try:
auto_mode = False
while True:
# Detect user input.
inputs = get_pin_input()
# Activate auto mode if the Green PB is pressed.
if auto_mode or inputs['green_button'] == True:
inputs['mode'] = "AUTO"
auto_mode = True
# Activate manual mode if the Yellow or Blue PB's are pressed.
if not auto_mode or inputs['yellow_button'] == True or inputs['blue_button'] == True:
inputs['mode'] = "MANUAL"
auto_mode = False
# Make any transitions based on mode and inputs.
outputs = check_state(inputs)
# Write the outputs which correspond to the desired state.
write_pin_output(outputs)
# Avoid maxxing out a single thread.
time.sleep(0.1)
# Cleanup on Exit.
finally:
GPIO.output(RELAY1_PIN, False)
GPIO.output(RELAY2_PIN, False)
GPIO.output(RELAY3_PIN, False)
GPIO.cleanup()