Pushing some work on automatic mode.
This commit is contained in:
43
automatic/input.py
Normal file
43
automatic/input.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#! env/bin/python3
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def get_pin_input():
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
# Get current time.
|
||||||
|
now = datetime.now()
|
||||||
|
hour = now.hour
|
||||||
|
minute = now.minute
|
||||||
|
|
||||||
|
# Define alias variables for input devices.
|
||||||
|
inputs = {
|
||||||
|
'green_button' : GPIO.input(PB1_BCM),
|
||||||
|
'yellow_button' : GPIO.input(PB2_BCM),
|
||||||
|
'blue_button' : GPIO.input(PB3_BCM),
|
||||||
|
'pump' : GPIO.input(RELAY1_PIN),
|
||||||
|
'lamp' : GPIO.input(RELAY3_PIN),
|
||||||
|
'hour' : hour,
|
||||||
|
'minute' : minute,
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputs
|
||||||
35
automatic/routine.py
Normal file
35
automatic/routine.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#! env/bin/python3
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import time
|
||||||
|
from input import get_pin_input
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setwarnings(False)
|
||||||
|
|
||||||
|
# If any error, Exit cleanly.
|
||||||
|
try:
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
inputs = get_pin_input()
|
||||||
|
|
||||||
|
if 6 < inputs['hour'] < 22:
|
||||||
|
GPIO.output(21,True)
|
||||||
|
else:
|
||||||
|
GPIO.output(21,False)
|
||||||
|
|
||||||
|
if inputs['minute']-30 < 0:
|
||||||
|
GPIO.output(26,True)
|
||||||
|
else:
|
||||||
|
GPIO.output(26,False)
|
||||||
|
|
||||||
|
# Cleanup on Exit.
|
||||||
|
finally:
|
||||||
|
|
||||||
|
GPIO.output(21,False)
|
||||||
|
GPIO.output(26,False)
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
@@ -70,5 +70,8 @@ if __name__ == "__main__":
|
|||||||
GPIO.output(RELAY1_PIN, pump_state)
|
GPIO.output(RELAY1_PIN, pump_state)
|
||||||
GPIO.output(RELAY3_PIN, lamp_state)
|
GPIO.output(RELAY3_PIN, lamp_state)
|
||||||
|
|
||||||
|
# Avoid running a single thread maxxed out.
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|||||||
Reference in New Issue
Block a user