Oct-13-2018, 01:01 PM
Hello.
I bought a four channel relay card for rpi's gpio, my idea is to use it for light in a quail-box.
I'd like to fake dusk and dawn by switching one weak led on at 6:00am and stronger number two at 6:30am
with the below script, it works, but does someone out there like to help me clean it up make it better?
I bought a four channel relay card for rpi's gpio, my idea is to use it for light in a quail-box.
I'd like to fake dusk and dawn by switching one weak led on at 6:00am and stronger number two at 6:30am
with the below script, it works, but does someone out there like to help me clean it up make it better?
#!/usr/bin/python import RPi.GPIO as GPIO import os from time import sleep # this lets us have a time delay (see line 15) import string from datetime import datetime GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering GPIO.setup(26, GPIO.OUT) # set GPIO18 as an output (LED) GPIO.setup(6, GPIO.OUT) # set GPIO18 as an output (LED) try: while True: now = datetime.now() h = string.atoi((now.strftime("%H"))) m = string.atoi((now.strftime("%M"))) s = string.atoi((now.strftime("%S"))) tid = (h*3600)+(m*60)+s # print tid if tid > ((6*3600)+(30*60)+0) and tid < ((22*3600)+(0*60)+0): # print "day" GPIO.output(26,1) GPIO.output(6,1) else: if tid > ((6*3600)+(0*60)+0) and tid < ((6*3600)+(30*60)+0): # print "dawn" GPIO.output(6,1) elif tid > ((22*3600)+(0*60)+0) and tid < ((22*3600)+(30*60)+0): # print "dusk" GPIO.output(6,1) else: # print "night" GPIO.output(26,0) GPIO.output(6,0) sleep(0.3) finally: GPIO.cleanup() #except Exception: # print("error") # os.system('chicken.py')