python - Raspberry Pi, ON turns the GPIO output off? -
for reason i'm having problems turning on , off outputs programs. if use following output turns on / off correctly
import rpi.gpio gpio gpio.setmode(gpio.bcm) gpio.setup(2, gpio.out) gpio.output(2, 1) time.sleep(2) gpio.output(2, 0)
but reason fish tank lighting program gpio.output(2, 0) (or false) turns relay on!? , same inverse
here program have called output incorrectly?
# lighting program --- import rpi.gpio gpio import datetime import time gpio.setmode(gpio.bcm) gpio.setup(2, gpio.out) # lights #declair lighting on/off times on_time_monday = open("monday_on.txt", 'r').read() off_time_monday = open("monday_off.txt", 'r').read() on_time_tuesday = open("tuesday_on.txt", 'r').read() off_time_tuesday = open("tuesday_off.txt", 'r').read() on_time_wednesday = open("wednesday_on.txt", 'r').read() off_time_wednesday = open("wednesday_off.txt", 'r').read() on_time_thursday = open("thursday_on.txt", 'r').read() off_time_thursday = open("thursday_off.txt", 'r').read() on_time_friday = open("friday_on.txt", 'r').read() off_time_friday = open("friday_off.txt", 'r').read() on_time_saturday = open("saturday_on.txt", 'r').read() off_time_saturday = open("saturday_off.txt", 'r').read() on_time_sunday = open("sunday_on.txt", 'r').read() off_time_sunday = open("sunday_off.txt", 'r').read() #find out day of week day = datetime.datetime.now() day_of_week = day.isoweekday() #find out time current_time = datetime.datetime.strftime(datetime.datetime.now(),'%h%m') #schedule on / off if (day_of_week == 1) , (current_time > on_time_monday , current_time < off_time_monday) : light_on_off = 1 elif (day_of_week == 2) , (current_time > on_time_tuesday , current_time < off_time_tuesday) : light_on_off = 1 elif (day_of_week == 3) , (current_time > on_time_wednesday , current_time < off_time_wednesday) : light_on_off = 1 elif (day_of_week == 4) , (current_time > on_time_thursday , current_time < off_time_thursday) : light_on_off = 1 elif (day_of_week == 5) , (current_time > on_time_friday , current_time < off_time_friday) : light_on_off = 1 elif (day_of_week == 6) , (current_time > on_time_saturday , current_time < off_time_saturday) : light_on_off = 1 elif (day_of_week == 7) , (current_time > on_time_sunday , current_time < off_time_sunday) : light_on_off = 1 else : light_on_off = 0 # call outputs on / off if light_on_off == 1: gpio.output(2, 0) print(light_on_off, "_high_") else: gpio.output(2, 1) print(light_on_off, "_low_")
Comments
Post a Comment