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.

90 lines
2.2KB

  1. import schedule
  2. import time
  3. import datetime
  4. import pifacedigitalio as p
  5. TREE = """
  6. * ,
  7. _/^\_
  8. < >
  9. * /.-.\ *
  10. * `/&\` *
  11. ,@.*;@,
  12. /_o.I %_\ *
  13. * (`'--:o(_@;
  14. /`;--.,__ `') *
  15. ;@`o % O,*`'`&\ *
  16. * (`'--)_@ ;o %'()\ *
  17. /`;--._`''--._O'@;
  18. /&*,()~o`;-.,_ `""`)
  19. * /`,@ ;+& () o*`;-';\ *
  20. (`""--.,_0 +% @' &()\ *
  21. /-.,_ ``''--....-'`) *
  22. * /@%;o`:;'--,.__ __.'\
  23. ;*,&(); @ % &^;~`"`o;@(); *
  24. /(); o^~; & ().o@*&`;&%O\
  25. jgs `"="==""==,,,.,="=="==="`
  26. __.----.(\-''#####---...___...-----._
  27. '` \)_`'''''`
  28. .--' ')
  29. o( )_-
  30. `'''` `
  31. """
  32. START = datetime.time(17, 0, 0)
  33. END = datetime.time(23, 59, 0)
  34. def timestamp():
  35. return datetime.datetime.now()
  36. def turn_on():
  37. """ Turn on the christmas tree """
  38. print("{} ON".format(timestamp()))
  39. p.digital_write(0, 1)
  40. def turn_off():
  41. """ Turn off the christmas tree """
  42. print("{} OFF".format(timestamp()))
  43. p.digital_write(0, 0)
  44. def check_connectivity():
  45. """ Flick the switch """
  46. print("Checking connectivity:")
  47. for i in range(2):
  48. turn_on()
  49. time.sleep(2)
  50. turn_off()
  51. time.sleep(2)
  52. # Turn on if we are in the correct interval
  53. now = datetime.datetime.now().time()
  54. if START <= now <= END:
  55. turn_on()
  56. if __name__ == "__main__":
  57. # Connect to PiFace
  58. print(TREE)
  59. p.init()
  60. # Check connectivity
  61. check_connectivity()
  62. # Message
  63. print()
  64. print("Starting scheduler:")
  65. print("Xmas enabled between {} and {}.".format(START.strftime("%H:%M"), END.strftime("%H:%M")))
  66. # Set up the schedule
  67. schedule.every().day.at(START.strftime("%H:%M")).do(turn_on)
  68. schedule.every().day.at(END.strftime("%H:%M")).do(turn_off)
  69. # Run the event loop
  70. while(True):
  71. schedule.run_pending()
  72. time.sleep(1)