[ create a new paste ] login | about

Link: http://codepad.org/OdUQuH1i    [ raw code | fork ]

Python, pasted on Apr 17:
#!/usr/bin/python2
import time
import datetime
from RPi import GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.HIGH)

	
Mon1On  = datetime.time(hour=23,minute=25,second=0)
Mon1Off = datetime.time(hour=23,minute=28,second=0)
Mon2On  = datetime.time(hour=23,minute=29,second=0)
Mon2Off = datetime.time(hour=23,minute=31,second=0)
Mon3On  = datetime.time(hour=23,minute=35,second=0)
Mon3Off = datetime.time(hour=23,minute=40,second=0)
Tue1On  = datetime.time(hour=8,minute=10,second=0)
Tue1Off = datetime.time(hour=8,minute=30,second=0)
Tue2On  = datetime.time(hour=12,minute=10,second=0)
Tue2Off = datetime.time(hour=12,minute=30,second=0)
Tue3On  = datetime.time(hour=18,minute=10,second=0)
Tue3Off = datetime.time(hour=18,minute=30,second=0)
Wed1On  = datetime.time(hour=8,minute=10,second=0)
Wed1Off = datetime.time(hour=8,minute=30,second=0)
Wed2On  = datetime.time(hour=12,minute=10,second=0)
Wed2Off = datetime.time(hour=12,minute=30,second=0)
Wed3On  = datetime.time(hour=18,minute=10,second=0)
Wed3Off = datetime.time(hour=18,minute=30,second=0)
Thu1On  = datetime.time(hour=8,minute=10,second=0)
Thu1Off = datetime.time(hour=8,minute=30,second=0)
Thu2On  = datetime.time(hour=12,minute=10,second=0)
Thu2Off = datetime.time(hour=12,minute=30,second=0)
Thu3On  = datetime.time(hour=18,minute=10,second=0)
Thu3Off = datetime.time(hour=18,minute=30,second=0)
Fri1On  = datetime.time(hour=8,minute=10,second=0)
Fri1Off = datetime.time(hour=8,minute=30,second=0)
Fri2On  = datetime.time(hour=12,minute=10,second=0)
Fri2Off = datetime.time(hour=12,minute=30,second=0)
Fri3On  = datetime.time(hour=18,minute=10,second=0)
Fri3Off = datetime.time(hour=18,minute=30,second=0)
Sat1On  = datetime.time(hour=8,minute=10,second=0)
Sat1Off = datetime.time(hour=8,minute=30,second=0)
Sat2On  = datetime.time(hour=12,minute=10,second=0)
Sat2Off = datetime.time(hour=12,minute=30,second=0)
Sat3On  = datetime.time(hour=18,minute=10,second=0)
Sat3Off = datetime.time(hour=18,minute=30,second=0)
Sun1On  = datetime.time(hour=23,minute=49,second=0)
Sun1Off = datetime.time(hour=23,minute=50,second=0)
Sun2On  = datetime.time(hour=23,minute=51,second=0)
Sun2Off = datetime.time(hour=23,minute=52,second=0)
Sun3On  = datetime.time(hour=23,minute=53,second=0)
Sun3Off = datetime.time(hour=23,minute=54,second=0)


OnTime = [Mon1On, Mon2On, Mon3On, Tue1On, Tue2On, Tue3On, Wed1On, Wed2On, Wed3On, Thu1On, Thu2On, Thu3On, Fri1On, Fri2On, Fri3On, Sat1On, Sat2On, Sat3On, Sun1On, Sun2On, Sun3On]
OffTime = [Mon1Off, Mon2Off, Mon3Off, Tue1Off, Tue2Off, Tue3Off, Wed1Off, Wed2Off, Wed3Off, Thu1Off, Thu2Off, Thu3Off, Fri1Off, Fri2Off, Fri3Off, Sat1Off, Sat2Off, Sat3Off, Sun1Off, Sun2Off, Sun3Off]

print "Start"
while True:
    currTime = datetime.datetime.now()
    currDay = currTime.weekday()
    
    if (currTime.hour - OnTime[currDay].hour == 0 and currTime.minute - OnTime[currDay].minute == 0 and currTime.second - OnTime[currDay].second == 0):
        GPIO.output(17, GPIO.LOW)
    elif (currTime.hour - OffTime[currDay].hour == 0 and currTime.minute - OffTime[currDay].minute == 0 and currTime.second - OffTime[currDay].second == 0):
        GPIO.output(17, GPIO.HIGH)

    time.sleep(1)

#EOF


Create a new paste based on this one


Comments: