Raspberry Pi,ON会关闭GPIO输出吗?

时间:2016-01-27 10:06:57

标签: python gpio

出于某种原因,我在使用我的程序打开和关闭输出时遇到问题。 如果我使用以下输出正确打开/关闭

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.OUT)
GPIO.output(2, 1)
time.sleep(2)        
GPIO.output(2, 0) 

但由于某种原因我的鱼缸照明程序GPIO.output(2,0)(或False)打开继电器!?反之亦然

这是我的程序,我输错了输出?

# Lighting Program ---

import RPi.GPIO as 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 what day of the week it is
day = datetime.datetime.now()
day_of_week = day.isoweekday()

#find out what time it is
Current_time = datetime.datetime.strftime(datetime.datetime.now(),'%H%M')

#Schedule on / off
if (day_of_week == 1) and (Current_time > on_time_Monday and Current_time < off_time_Monday) :
    Light_on_off = 1
elif (day_of_week == 2) and (Current_time > on_time_Tuesday and Current_time < off_time_Tuesday) :
    Light_on_off = 1
elif (day_of_week == 3) and (Current_time > on_time_Wednesday and Current_time < off_time_Wednesday) :
    Light_on_off = 1
elif (day_of_week == 4) and (Current_time > on_time_Thursday and Current_time < off_time_Thursday) :
    Light_on_off = 1
elif (day_of_week == 5) and (Current_time > on_time_Friday and Current_time < off_time_Friday) :
    Light_on_off = 1
elif (day_of_week == 6) and (Current_time > on_time_Saturday and Current_time < off_time_Saturday) :
    Light_on_off = 1
elif (day_of_week == 7) and (Current_time > on_time_Sunday and 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_")

0 个答案:

没有答案