55"""
66import time
77import board
8+ import neopixel
89from adafruit_pyportal import PyPortal
910from adafruit_bitmap_font import bitmap_font
1011from adafruit_display_text .Label import Label
1112
13+
14+ # Type in time to get up
15+ input_wake_up_time = "8:00A"
16+
17+ BRIGHTNESS = 0
18+ MIN_BRIGHTNESS = 0
19+ MAX_BRIGHTNESS = 0.2 # brightness above 0.2 crashes pyportal
20+
21+ strip = neopixel .NeoPixel (board .D4 , 144 , brightness = BRIGHTNESS )
22+
23+ strip .brightness = MIN_BRIGHTNESS
24+
25+
26+ light_minutes = 30
27+
1228# Set to True for '12 hour + AM/PM' time, set to false for 24 hour time
1329AM_PM = True
1430
2743info_font = bitmap_font .load_font (cwd + "/fonts/Nunito-Black-17.bdf" )
2844info_font .load_glyphs (b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ ' )
2945
30- # Type in time to get up
31- input_wake_up_time = "6:30"
32- input_wake_up_time_text = "Wake up at: " + input_wake_up_time + "am"
46+
47+ input_wake_up_time_text = "Wake up 30 min after: " + input_wake_up_time
3348#light_on_time_text = "Light starting at: " # - 30 minutes? how?
3449
3550time_color = 0xFFFFFF
36- time_position = (0 ,130 )
51+ time_position = (75 ,130 )
3752time_textarea = Label (big_font , max_glyphs = 15 , color = time_color ,
3853 x = time_position [0 ], y = time_position [1 ])
3954
4661wakeup_time_textarea .text = input_wake_up_time_text
4762pyportal .splash .append (wakeup_time_textarea )
4863
49- refresh_time = None
64+ #def subtract30min(time_raw):
5065
51- while True :
52- # only query the online time once per hour (and on first run)
53- if (not refresh_time ) or (time .monotonic () - refresh_time ) > 3600 :
54- try :
55- print ("Getting time from internet!" )
56- pyportal .get_local_time ()
57- refresh_time = time .monotonic ()
58- except RuntimeError as e :
59- print ("Some error occured, retrying! -" , e )
60- continue
61- print (time .monotonic ())
66+
67+ def displayTime ():
6268 now = time .localtime ()
6369 hour , minute = now [3 :5 ]
6470 print (now )
7581 if hour == 0 :
7682 hour = 12
7783 if hour < 10 :
78- format_str = " " + format_str
84+ format_str = "" + format_str
7985 time_str = format_str % (hour , minute )
8086 time_textarea .text = time_str
8187
88+ return time_str
89+
90+
91+ refresh_time = None
92+
93+ while True :
94+ # only query the online time once per hour (and on first run)
95+ if (not refresh_time ) or (time .monotonic () - refresh_time ) > 3600 :
96+ try :
97+ print ("Getting time from internet!" )
98+ pyportal .get_local_time ()
99+ refresh_time = time .monotonic ()
100+ except RuntimeError as e :
101+ print ("Some error occured, retrying! -" , e )
102+ continue
103+
104+ time_str_text = displayTime ()
105+
106+ print (time_str_text )
107+ print (input_wake_up_time )
108+
109+ # If wake up time - 30 minutes equals current time, start the light
110+ if time_str_text is input_wake_up_time :
111+ print ("Starting wake up light" )
112+ for i in range (light_minutes - 1 ):
113+ BRIGHTNESS = BRIGHTNESS + (MAX_BRIGHTNESS / light_minutes ) # max 0.25, min 0.0
114+ print (BRIGHTNESS )
115+
116+ strip .fill ((255 , 255 , 255 ))
117+ strip .brightness = BRIGHTNESS
118+
119+ displayTime ()
120+
121+ time .sleep (60 )
122+ while not pyportal .touchscreen .touch_point :
123+ pass
124+ strip .brightness = MIN_BRIGHTNESS
125+
82126 # update every 15 seconds
83127 time .sleep (15 )
0 commit comments