1212
1313
1414# Type in time to get up
15- input_wake_up_time = "8:00A"
16-
17- board .DISPLAY .brightness = 0.1
15+ input_wake_up_time = "7:45P"
1816
1917BRIGHTNESS = 0
2018MIN_BRIGHTNESS = 0
21- MAX_BRIGHTNESS = 0.2 # brightness above 0.2 crashes pyportal
19+ MAX_BRIGHTNESS = 0.5 # brightness above 0.2 crashes pyportal
20+
21+ strip = neopixel .NeoPixel (board .D3 , 40 , brightness = BRIGHTNESS )
2222
23- strip = neopixel . NeoPixel ( board . D4 , 144 , brightness = BRIGHTNESS )
23+ strip . fill (( 0 ) )
2424
2525strip .brightness = MIN_BRIGHTNESS
26+ strip .show ()
2627
2728
2829light_minutes = 30
4647info_font .load_glyphs (b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ ' )
4748
4849
49- input_wake_up_time_text = "Wake up 30 min after: " + input_wake_up_time
50+ input_wake_up_time_text = "Wake up 30 min after " + input_wake_up_time
5051#light_on_time_text = "Light starting at: " # - 30 minutes? how?
5152
5253time_color = 0xFFFFFF
5960wakeup_time_textarea = Label (info_font , max_glyphs = 30 , color = wakeup_time_color ,
6061 x = wakeup_time_position [0 ], y = wakeup_time_position [1 ])
6162
63+ light_on_time_color = 0xFFFFFF
64+ light_on_time_position = (15 ,220 )
65+ light_on_time_textarea = Label (info_font , max_glyphs = 30 , color = light_on_time_color ,
66+ x = light_on_time_position [0 ], y = light_on_time_position [1 ])
67+
6268pyportal .splash .append (time_textarea )
6369wakeup_time_textarea .text = input_wake_up_time_text
6470pyportal .splash .append (wakeup_time_textarea )
71+ pyportal .splash .append (light_on_time_textarea )
6572
66- #def subtract30min(time_raw):
6773
74+ '''
75+
76+ def subtract30min(time_raw):
77+ now = time.localtime()
78+ hour, minute = now[3:5]
79+ if time_raw[4] >= 30:
80+ minute = time_raw[4] - 30
81+ # display the time in a nice big font
82+ format_str = "%d:%02d"
83+ if AM_PM:
84+ if hour >= 12:
85+ hour -= 12
86+ format_str = format_str+"P"
87+ else:
88+ format_str = format_str+"A"
89+ if hour == 0:
90+ hour = 12
91+ if hour < 10:
92+ format_str = ""+format_str
93+ sub30_str = format_str % (hour, minute)
94+ light_on_time_textarea.text = "Light starting at: " + sub30_str
95+ return sub30_str
96+
97+
98+ elif time_raw[4] < 30:
99+ minute = time_raw[4] + 30
100+ hour = hour - 1
101+ format_str = "%d:%02d"
102+ if AM_PM:
103+ if hour >= 12:
104+ hour -= 12
105+ format_str = format_str+"P"
106+ else:
107+ format_str = format_str+"A"
108+ if hour == 0:
109+ hour = 12
110+ if hour < 10:
111+ format_str = ""+format_str
112+ sub30_str = format_str % (hour, minute)
113+ light_on_time_textarea.text = "Light starting at: " + sub30_str
114+ return sub30_str
115+
116+ '''
68117
69118def displayTime ():
70119 now = time .localtime ()
@@ -89,10 +138,12 @@ def displayTime():
89138
90139 return time_str
91140
92-
93141refresh_time = None
94142
143+ pyportal .set_backlight (0.1 )
144+
95145while True :
146+
96147 # only query the online time once per hour (and on first run)
97148 if (not refresh_time ) or (time .monotonic () - refresh_time ) > 3600 :
98149 try :
@@ -108,20 +159,33 @@ def displayTime():
108159 print (time_str_text )
109160 print (input_wake_up_time )
110161
162+
163+ currentHour = time .localtime ()
164+
165+ # if after 9am and before 9pm light is = 0.8
166+ if currentHour [3 ] > 9 and currentHour [3 ] < 21 :
167+ pyportal .set_backlight (0.8 )
168+ # if after 9pm and before 9am light = 0.1
169+ else :
170+ pyportal .set_backlight (0.1 )
171+
172+
173+ # sub30 = subtract30min(currentHour) # input needs to be input_wake_up_time_text
174+
175+
111176 # If wake up time - 30 minutes equals current time, start the light
112177 if time_str_text is input_wake_up_time :
113178 print ("Starting wake up light" )
114179 for i in range (light_minutes - 1 ):
115180 BRIGHTNESS = BRIGHTNESS + (MAX_BRIGHTNESS / light_minutes ) # max 0.25, min 0.0
116181 print (BRIGHTNESS )
117-
118182 strip .fill ((255 , 255 , 255 ))
119183 strip .brightness = BRIGHTNESS
120-
121184 displayTime ()
122-
123- time .sleep (60 )
185+ time .sleep (1 )
124186 while not pyportal .touchscreen .touch_point :
187+ displayTime ()
188+ time .sleep (60 ) # 60 for once per min
125189 pass
126190 strip .brightness = MIN_BRIGHTNESS
127191
0 commit comments