11"""
22This example uses a PyPortal and rgbw leds for a simple "wake up" light.
33The strip starts to brighten 30 minutes before set wake up time.
4- This program assumes a neopixel strip is attached to D3 on the Adafruit PyPortal.
4+ This program assumes a neopixel strip is attached to D4 on the Adafruit PyPortal.
55"""
66import time
77import board
1111from adafruit_display_text .Label import Label
1212
1313# Type in time to get up each day of the week
14- up_time_monday = "6:30A"
15- up_time_tuesday = "6:30A"
16- up_time_wednesday = "6:30A"
17- up_time_thursday = "6:30A"
18- up_time_friday = "6:30A"
14+ default_wake_up = "6:30A"
15+ up_time_monday = default_wake_up
16+ up_time_tuesday = default_wake_up
17+ up_time_wednesday = default_wake_up
18+ up_time_thursday = default_wake_up
19+ up_time_friday = default_wake_up
1920up_time_saturday = "10:00A"
2021up_time_sunday = "10:00A"
2122
6869pyportal .splash .append (wakeup_time_textarea )
6970pyportal .splash .append (light_on_time_textarea )
7071
71- # determines which day to pull wake up time from
7272def whichDay ():
7373 now = time .localtime ()
74+ current_hour , current_minutes = now [3 :5 ]
7475 current_day = now [6 ]
75- if current_day == 0 :
76- input_wake_up_time = up_time_monday
77- elif current_day == 1 :
78- input_wake_up_time = up_time_tuesday
79- elif current_day == 2 :
80- input_wake_up_time = up_time_wednesday
81- elif current_day == 3 :
82- input_wake_up_time = up_time_thursday
83- elif current_day == 4 :
84- input_wake_up_time = up_time_friday
85- elif current_day == 5 :
86- input_wake_up_time = up_time_saturday
87- elif current_day == 6 :
88- input_wake_up_time = up_time_sunday
76+ wake_up_hour , wake_up_minutes = default_wake_up .split (":" )
77+ wake_up_hour = int (wake_up_hour )
78+ wake_up_minutes = int (wake_up_minutes [:- 1 ])
79+ print (wake_up_hour , ":" , wake_up_minutes )
80+ # if it's after midnight and before the default wakeup time, display the wake up time of today
81+ if current_hour < wake_up_hour and current_minutes < wake_up_minutes :
82+ print ("midnight" )
83+ if current_day == 0 :
84+ input_wake_up_time = up_time_monday
85+ elif current_day == 1 :
86+ input_wake_up_time = up_time_tuesday
87+ elif current_day == 2 :
88+ input_wake_up_time = up_time_wednesday
89+ elif current_day == 3 :
90+ input_wake_up_time = up_time_thursday
91+ elif current_day == 4 :
92+ input_wake_up_time = up_time_friday
93+ elif current_day == 5 :
94+ input_wake_up_time = up_time_saturday
95+ elif current_day == 6 :
96+ input_wake_up_time = up_time_sunday
97+
98+ else : # set wake up time to the next day's wake up time the night before
99+ if current_day == 6 :
100+ input_wake_up_time = up_time_monday
101+ elif current_day == 0 :
102+ input_wake_up_time = up_time_tuesday
103+ elif current_day == 1 :
104+ input_wake_up_time = up_time_wednesday
105+ elif current_day == 2 :
106+ input_wake_up_time = up_time_thursday
107+ elif current_day == 3 :
108+ input_wake_up_time = up_time_friday
109+ elif current_day == 4 :
110+ input_wake_up_time = up_time_saturday
111+ elif current_day == 5 :
112+ input_wake_up_time = up_time_sunday
89113 input_wake_up_time_text = "Wake up at " + input_wake_up_time
90114 wakeup_time_textarea .text = input_wake_up_time_text
91115 return input_wake_up_time
92116
93- # subtract 30 min from given time to tell program when to start lights
94117def subtract30min (time_before ):
95118 hours_before , minutes_before = time_before .split (":" )
96119 AM_PM_str = minutes_before [- 1 :]
@@ -113,7 +136,6 @@ def subtract30min(time_before):
113136 if hours_before == 0 :
114137 hours_after = 12
115138 sub30_str = format_str % (hours_after , minutes_after )
116- light_on_time_textarea .text = "Light starting at: " + sub30_str
117139 elif minutes_before < 30 :
118140 minutes_after = minutes_before + 30
119141 hours_after = hours_before - 1
@@ -122,16 +144,14 @@ def subtract30min(time_before):
122144 hours_after = hours_after - 12
123145 format_str = format_str + "P"
124146 else :
125- hours_after = hours_before
126147 format_str = format_str + "A"
127148 if hours_before == 0 :
128149 hours_after = 11
129150 format_str = format_str [:- 1 ]+ "P"
130151 sub30_str = format_str % (hours_after , minutes_after )
131- light_on_time_textarea .text = "Light starting at: " + sub30_str
152+ light_on_time_textarea .text = "Light starting at: " + sub30_str
132153 return sub30_str
133154
134- # display current time
135155def displayTime ():
136156 now = time .localtime ()
137157 hour , minute = now [3 :5 ]
@@ -163,28 +183,30 @@ def displayTime():
163183 print ("Some error occured, retrying! -" , e )
164184 continue
165185 time_str_text = displayTime ()
186+ print (time_str_text )
166187 currentHour = time .localtime ()
167- # if after 9am and before 9pm backlight is = 0.8
188+ # if after 9am and before 9pm light is = 0.8
168189 if currentHour [3 ] > 9 and currentHour [3 ] < 21 :
169190 pyportal .set_backlight (0.8 )
170- # if after 9pm and before 9am backlight = 0.1
191+ # if after 9pm and before 9am light = 0.1
171192 else :
172193 pyportal .set_backlight (0.1 )
173194 wake_up_time = whichDay ()
174195 start_light_time = subtract30min (wake_up_time )
196+ print (start_light_time )
175197 # If wake up time - 30 minutes equals current time, start the light
176198 if time_str_text == start_light_time :
177199 print ("Starting wake up light" )
178200 for i in range (light_minutes - 1 ):
179- BRIGHTNESS = BRIGHTNESS + (MAX_BRIGHTNESS / light_minutes )
201+ BRIGHTNESS = BRIGHTNESS + (MAX_BRIGHTNESS / light_minutes ) # max 0.25, min 0.0
180202 strip .fill (WHITE )
181203 strip .brightness = BRIGHTNESS
182204 displayTime ()
183- time .sleep (60 ) # increase brightness once per min
205+ time .sleep (1 ) # 60 for once per min
184206 while not pyportal .touchscreen .touch_point : # turn strip off
185207 displayTime ()
186208 time .sleep (1 )
187209 continue
188210 strip .brightness = MIN_BRIGHTNESS
189211 # update every 15 seconds
190- time .sleep (15 )
212+ time .sleep (15 )
0 commit comments