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.

92 line
2.1KB

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