|
- import time
- import datetime
- import pifacedigitalio as p
-
- # Configures interval
- START = datetime.time(17, 0, 0)
- END = datetime.time(23, 59, 0)
-
- TREE = """
- * ,
- _/^\_
- < >
- * /.-.\ *
- * `/&\` *
- ,@.*;@,
- /_o.I %_\ *
- * (`'--:o(_@;
- /`;--.,__ `') *
- ;@`o % O,*`'`&\ *
- * (`'--)_@ ;o %'()\ *
- /`;--._`''--._O'@;
- /&*,()~o`;-.,_ `""`)
- * /`,@ ;+& () o*`;-';\ *
- (`""--.,_0 +% @' &()\ *
- /-.,_ ``''--....-'`) *
- * /@%;o`:;'--,.__ __.'\
- ;*,&(); @ % &^;~`"`o;@(); *
- /(); o^~; & ().o@*&`;&%O\
- jgs `"="==""==,,,.,="=="==="`
- __.----.(\-''#####---...___...-----._
- '` \)_`'''''`
- .--' ')
- o( )_-
- `'''` `
- """
-
-
- def timestamp():
- """ Get a 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 update():
- """ Updates the state """
- now = datetime.datetime.now().time()
- if START <= now <= END:
- turn_on()
- else:
- turn_off()
-
-
- def check_connectivity():
- """ Flick the switch """
- print("Checking connectivity:")
- for i in range(2):
- turn_on()
- time.sleep(2)
- turn_off()
- time.sleep(2)
-
-
- if __name__ == "__main__":
- # Connect to PiFace
- print(TREE)
- p.init()
-
- # Check connectivity
- check_connectivity()
-
- # Message
- print()
- print("Starting scheduler:")
- print("Xmas enabled between {} and {}.".format(
- START.strftime("%H:%M"), END.strftime("%H:%M")))
-
- # Run the event loop
- while (True):
- update()
- time.sleep(60)
|