Christmas tree light sequencer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 line
876B

  1. import schedule
  2. import time
  3. import datetime
  4. import pifacedigitalio as p
  5. def timestamp():
  6. return datetime.datetime.now()
  7. def turn_on():
  8. """ Turn on the christmas tree """
  9. print("{} ON".format(timestamp()))
  10. p.digital_write(0, 1)
  11. def turn_off():
  12. """ Turn off the christmas tree """
  13. print("{} OFF".format(timestamp()))
  14. p.digital_write(0, 0)
  15. def check_connectivity():
  16. """ Flick the switch """
  17. for i in range(10):
  18. turn_on()
  19. time.sleep(.3)
  20. turn_off()
  21. time.sleep(.3)
  22. if __name__ == "__main__":
  23. # Connect to PiFace
  24. p.init()
  25. # Check connectivity
  26. check_connectivity()
  27. # Set up the schedule
  28. schedule.every().day.at("17:00").do(turn_on)
  29. schedule.every().day.at("23:59").do(turn_off)
  30. # Run the event loop
  31. while(True):
  32. schedule.run_pending()
  33. time.sleep(1)