1010from adafruit_bitmap_font import bitmap_font
1111from adafruit_display_text .Label import Label
1212
13-
14- # Type in time to get up
15- input_wake_up_time = "12:29A"
16-
13+ # Type in time to get up each day of the week
14+ input_wake_up_time = ""
15+ up_time_monday = "6:30A"
16+ up_time_tuesday = "6:30A"
17+ up_time_wednesday = "6:30A"
18+ up_time_thursday = "6:30A"
19+ up_time_friday = "6:30A"
20+ up_time_saturday = "10:00A"
21+ up_time_sunday = "10:00A"
22+
23+ # set neopixel min and max brightness
1724BRIGHTNESS = 0
1825MIN_BRIGHTNESS = 0
1926MAX_BRIGHTNESS = 0.85
20-
27+ #initialize neopixel strip
2128strip = neopixel .NeoPixel (board .D3 , 40 , brightness = BRIGHTNESS )
22-
23- strip .fill ((0 ))
24-
25- strip .brightness = MIN_BRIGHTNESS
26- strip .show ()
27-
28-
29+ strip .fill (0 )
30+ # number of minutes it takes for strip to fade from min to max
2931light_minutes = 30
3032
31- # Set to True for '12 hour + AM/PM' time, set to false for 24 hour time
32- AM_PM = True
33-
3433# determine the current working directory
3534# needed so we know where to find files
3635cwd = ("/" + __file__ ).rsplit ('/' , 1 )[0 ]
36+
3737# Initialize the pyportal object and let us know what data to fetch and where
3838# to display it
39-
4039pyportal = PyPortal (status_neopixel = board .NEOPIXEL ,
4140 default_bg = 0x000000 )
4241
4645info_font = bitmap_font .load_font (cwd + "/fonts/Nunito-Black-17.bdf" )
4746info_font .load_glyphs (b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ ' )
4847
49-
50- input_wake_up_time_text = "Wake up at " + input_wake_up_time
51- #light_on_time_text = "Light starting at: " # - 30 minutes? how?
52-
5348time_color = 0xFFFFFF
5449time_position = (75 ,130 )
5550time_textarea = Label (big_font , max_glyphs = 15 , color = time_color ,
6661 x = light_on_time_position [0 ], y = light_on_time_position [1 ])
6762
6863pyportal .splash .append (time_textarea )
69- wakeup_time_textarea .text = input_wake_up_time_text
7064pyportal .splash .append (wakeup_time_textarea )
7165pyportal .splash .append (light_on_time_textarea )
7266
67+ def whichDay ():
68+ now = time .localtime ()
69+ current_day = now [6 ]
70+ if current_day == 0 :
71+ input_wake_up_time = up_time_monday
72+ elif current_day == 1 :
73+ input_wake_up_time = up_time_tuesday
74+ elif current_day == 2 :
75+ input_wake_up_time = up_time_wednesday
76+ elif current_day == 3 :
77+ input_wake_up_time = up_time_thursday
78+ elif current_day == 4 :
79+ input_wake_up_time = up_time_friday
80+ elif current_day == 5 :
81+ input_wake_up_time = up_time_saturday
82+ elif current_day == 6 :
83+ input_wake_up_time = up_time_sunday
84+ input_wake_up_time_text = "Wake up at " + input_wake_up_time
85+ wakeup_time_textarea .text = input_wake_up_time_text
86+ return input_wake_up_time
87+
7388def subtract30min (time_before ):
7489 hours_before , minutes_before = time_before .split (":" )
7590 AM_PM_str = minutes_before [- 1 :]
@@ -78,51 +93,36 @@ def subtract30min(time_before):
7893 hours_before = int (hours_before ) + 12
7994 elif ((hours_before == '12' ) and (AM_PM_str == 'A' )):
8095 hours_before = 0
81- print ("Its midnight" )
8296 else :
8397 hours_before = int (hours_before )
84- print ("else" )
85- print (AM_PM_str )
86- print (hours_before )
87- print (minutes_before )
8898 if minutes_before >= 30 :
8999 minutes_after = minutes_before - 30
90100 # display the time in a nice big font
91101 format_str = "%d:%02d"
92- if AM_PM :
93- if hours_before >= 12 :
94- hours_after = hours_before - 12
95- format_str = format_str + "P"
96- else :
97- hours_after = hours_before
98- format_str = format_str + "A"
99- if hours_before == 0 :
100- hours_after = 12
101- if hours_before < 10 :
102- format_str = "" + format_str
103- print (hours_after )
104- print (minutes_after )
102+ if hours_before >= 12 :
103+ hours_after = hours_before - 12
104+ format_str = format_str + "P"
105+ else :
106+ hours_after = hours_before
107+ format_str = format_str + "A"
108+ if hours_before == 0 :
109+ hours_after = 12
105110 sub30_str = format_str % (hours_after , minutes_after )
106111 light_on_time_textarea .text = "Light starting at: " + sub30_str
107112 return sub30_str
108113 elif minutes_before < 30 :
109114 minutes_after = minutes_before + 30
110115 hours_after = hours_before - 1
111116 format_str = "%d:%02d"
112- if AM_PM :
113- if hours_before >= 12 :
114- hours_after = hours_before - 12
115- format_str = format_str + "P"
116- else :
117- hours_after = hours_before
118- format_str = format_str + "A"
119- if hours_before == 0 :
120- hours_after = 11
121- format_str = format_str [:- 1 ]+ "P"
122- if hours_before < 10 :
123- format_str = "" + format_str
124- print (hours_after )
125- print (minutes_after )
117+ if hours_before >= 12 :
118+ hours_after = hours_before - 12
119+ format_str = format_str + "P"
120+ else :
121+ hours_after = hours_before
122+ format_str = format_str + "A"
123+ if hours_before == 0 :
124+ hours_after = 11
125+ format_str = format_str [:- 1 ]+ "P"
126126 sub30_str = format_str % (hours_after , minutes_after )
127127 light_on_time_textarea .text = "Light starting at: " + sub30_str
128128 return sub30_str
@@ -132,31 +132,21 @@ def displayTime():
132132 hour , minute = now [3 :5 ]
133133 print (now )
134134 print ("Current time: %02d:%02d" % (hour , minute ))
135-
136135 # display the time in a nice big font
137136 format_str = "%d:%02d"
138- if AM_PM :
139- if hour >= 12 :
140- hour -= 12
141- format_str = format_str + "P"
142- else :
143- format_str = format_str + "A"
144- if hour == 0 :
145- hour = 12
146- if hour < 10 :
147- format_str = "" + format_str
137+ if hour >= 12 :
138+ hour -= 12
139+ format_str = format_str + "P"
140+ else :
141+ format_str = format_str + "A"
142+ if hour == 0 :
143+ hour = 12
148144 time_str = format_str % (hour , minute )
149145 time_textarea .text = time_str
150-
151146 return time_str
152147
153148refresh_time = None
154149
155- pyportal .set_backlight (0.1 )
156-
157-
158-
159-
160150while True :
161151
162152 # only query the online time once per hour (and on first run)
@@ -168,32 +158,23 @@ def displayTime():
168158 except RuntimeError as e :
169159 print ("Some error occured, retrying! -" , e )
170160 continue
171-
172161 time_str_text = displayTime ()
173-
174162 print (time_str_text )
175- print (input_wake_up_time )
176-
177-
178163 currentHour = time .localtime ()
179-
180164 # if after 9am and before 9pm light is = 0.8
181165 if currentHour [3 ] > 9 and currentHour [3 ] < 21 :
182166 pyportal .set_backlight (0.8 )
183167 # if after 9pm and before 9am light = 0.1
184168 else :
185169 pyportal .set_backlight (0.1 )
186-
187-
170+ input_wake_up_time = whichDay ()
188171 # sub30 = subtract30min(currentHour) # input needs to be input_wake_up_time_text
189172 subtract30min (input_wake_up_time )
190-
191173 # If wake up time - 30 minutes equals current time, start the light
192174 if time_str_text is input_wake_up_time :
193175 print ("Starting wake up light" )
194176 for i in range (light_minutes - 1 ):
195177 BRIGHTNESS = BRIGHTNESS + (MAX_BRIGHTNESS / light_minutes ) # max 0.25, min 0.0
196- print (BRIGHTNESS )
197178 strip .fill ((255 , 255 , 255 ))
198179 strip .brightness = BRIGHTNESS
199180 displayTime ()
@@ -203,6 +184,5 @@ def displayTime():
203184 time .sleep (1 )
204185 pass
205186 strip .brightness = MIN_BRIGHTNESS
206-
207187 # update every 15 seconds
208188 time .sleep (15 )
0 commit comments