| @@ -1,10 +1,46 @@ | |||||
| from time import sleep | |||||
| import schedule | |||||
| import time | |||||
| import datetime | |||||
| import pifacedigitalio as p | import pifacedigitalio as p | ||||
| p.init() | |||||
| while(True): | |||||
| p.digital_write(0,1) #turn on | |||||
| sleep(3) | |||||
| p.digital_write(0,0) #turn off | |||||
| sleep(5) | |||||
| def timestamp(): | |||||
| return datetime.datetime.now() | |||||
| def turn_on(): | |||||
| """ Turn on the christmas tree """ | |||||
| print("{} ON".format(timestamp())) | |||||
| p.digital_write(0, 1) | |||||
| def turn_off(): | |||||
| """ Turn off the christmas tree """ | |||||
| print("{} OFF".format(timestamp())) | |||||
| p.digital_write(0, 0) | |||||
| def check_connectivity(): | |||||
| """ Flick the switch """ | |||||
| for i in range(10): | |||||
| turn_on() | |||||
| time.sleep(.3) | |||||
| turn_off() | |||||
| time.sleep(.3) | |||||
| if __name__ == "__main__": | |||||
| # Connect to PiFace | |||||
| p.init() | |||||
| # Check connectivity | |||||
| check_connectivity() | |||||
| # Set up the schedule | |||||
| schedule.every().day.at("17:00").do(turn_on) | |||||
| schedule.every().day.at("23:59").do(turn_off) | |||||
| # Run the event loop | |||||
| while(True): | |||||
| schedule.run_pending() | |||||
| time.sleep(1) | |||||