May-02-2020, 02:29 AM
Brand new to Python. If I want to pause the execution of my program for an hour, is sleep() the appropriate function to call? Do I have to express the value passed to sleep()in secs or can I use mins? I'm using a RPi 3B+ with a relay HAT. Thanks for helping.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(32,GPIO.OUT) #Pin 32 = Relay #1 (Pump) 20 Min 1200 Sec
GPIO.output(32,GPIO.HIGH) #HIGH = OFF
GPIO.setup(36,GPIO.OUT) #Pin 36 = Relay #2(Solenoid A) 45 Min, 2700 Sec
GPIO.output(36,GPIO.HIGH)
GPIO.setup(38,GPIO.OUT) #Pin 38 = Relay #3(Solenoid B) 45 Min
GPIO.output(38,GPIO.HIGH)
GPIO.setup(40,GPIO.OUT) #Pin 40 = Relay #4(unused)
GPIO.output(40,GPIO.HIGH)
while True:
try:
GPIO.output(36,GPIO.LOW) #Open Sol A
GPIO.output(32,GPIO.LOW) #Pump ON
time.sleep(1200) #Flood bed A for 20 min
GPIO.output(38,GPIO.LOW) #Open Sol B
GPIO.output(36,GPIO.HIGH) #Close Sol A
time.sleep(1200) #Flood bed B for 20 min
GPIO.output(32,GPIO.HIGH) #Pump OFF
GPIO.output(38,GPIO.HIGH) #Close Sol B
time.sleep(1800) #Allow for complete drainage of beds
except KeyboardInterrupt:
