|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import schedule
- import time
- import datetime
- import pifacedigitalio as p
-
-
- 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)
|