2016-11-11 94 views
-1

for set hour_on | hour_off,有在配置这些命令:在08:30打开灯WebIOPi raspberry pi 3

HOUR_ON = 8 # Turn Light ON at 08:00 
HOUR_OFF = 18 # Turn Light OFF at 18:00 

而且它的确定,但如果我将在08:30设置HOUR_ON

+0

你试过了吗? –

回答

1

您必须修改示例程序以添加分钟功能。 有关Python日期操作的详细信息,请参阅this page

This page说明如何修改loop函数添加minutes功能,

def loop(): 
    # Get the current time 
    now = datetime.time(datetime.datetime.now().hour, datetime.datetime.now().minute) 

    # Automatically switch on LED 
    if ((now.hour == HOUR_ON.hour) and (now.minute == HOUR_ON.minute) and (now.second == 0)): 
     if (GPIO.digitalRead(LIGHT) == GPIO.LOW): 
      GPIO.digitalWrite(LIGHT, GPIO.HIGH) 

    # Automatically switch off LED 
    if ((now.hour == HOUR_OFF.hour) and (now.minute == HOUR_OFF.minute) and (now.second == 0)): 
     if (GPIO.digitalRead(LIGHT) == GPIO.HIGH): 
      GPIO.digitalWrite(LIGHT, GPIO.LOW) 

    # Repeat every 1 second 
    webiopi.sleep(1)