77from adafruit_esp32spi import adafruit_esp32spi , adafruit_esp32spi_wifimanager
88import adafruit_requests as requests
99import digitalio
10- import analogio
10+ from analogio import AnalogIn
1111from adafruit_pyportal import PyPortal
1212from adafruit_bitmap_font import bitmap_font
1313from adafruit_display_text import label
2020the secrets dictionary must contain 'ssid' and 'password' at a minimum""" )
2121 raise
2222
23+ # Colors for each label
24+ LABEL_DAY_COLOR = 0xFFFFFF
25+ LABEL_TIME_COLOR = 0x8f42f4
26+
27+ # the current working directory (where this file is)
28+ cwd = ("/" + __file__ ).rsplit ('/' , 1 )[0 ]
29+ background = None
30+ # un-comment to set background image
31+ # background = cwd+"/background.bmp"
32+
2333# Descriptions of each hour
2434# https://github.com/mwfisher3/QuarantineClock/blob/master/today.html
2535time_name = ["midnight-ish" , "late night" , "late" , "super late" ,
2939 "late afternoon" ,"early evening" ,"early evening" ,"dusk-ish" ,
3040 "evening" ,"evening" ,"late evening" ,"late evening" ]
3141
32-
3342esp32_cs = digitalio .DigitalInOut (board .ESP_CS )
3443esp32_ready = digitalio .DigitalInOut (board .ESP_BUSY )
3544esp32_reset = digitalio .DigitalInOut (board .ESP_RESET )
3847esp = adafruit_esp32spi .ESP_SPIcontrol (spi , esp32_cs , esp32_ready , esp32_reset , debug = False )
3948requests .set_socket (socket , esp )
4049
41-
4250def wday_to_weekday_name (tm_wday ):
4351 """Returns the name of the weekday based on tm_wday value.
4452 :param int tm_wday: Days since Sunday.
@@ -52,11 +60,15 @@ def wday_to_weekday_name(tm_wday):
5260 4 : "Friday" ,
5361 5 : "Saturday" ,
5462 6 : "Sunday" ,}
55- return switch .get (tm_wday , "Not found" )
63+ return switch .get (tm_wday , "Day not found" )
5664
5765# initialize pyportal
5866pyportal = PyPortal (esp = esp ,
59- external_spi = spi )
67+ external_spi = spi ,
68+ default_bg = None )
69+
70+ # set pyportal's backlight brightness
71+ pyportal .set_backlight (0.7 )
6072
6173if esp .status == adafruit_esp32spi .WL_IDLE_STATUS :
6274 print ("ESP32 found and in idle mode" )
@@ -72,19 +84,19 @@ def wday_to_weekday_name(tm_wday):
7284 continue
7385
7486# Set the font and preload letters
75- font_large = bitmap_font .load_font ("/fonts/Helvetica-Bold-36 .bdf" )
87+ font_large = bitmap_font .load_font ("/fonts/Helvetica-Bold-44 .bdf" )
7688font_small = bitmap_font .load_font ("/fonts/Helvetica-Bold-24.bdf" )
7789font_large .load_glyphs (b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ' )
7890font_small .load_glyphs (b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()' )
7991
8092# Set up label for the day
81- label_day = label .Label (font_large , color = 0xFFFFFF , max_glyphs = 200 )
82- label_day .x = board .DISPLAY .width // 5
83- label_day .y = 70
93+ label_day = label .Label (font_large , color = LABEL_DAY_COLOR , max_glyphs = 200 )
94+ label_day .x = board .DISPLAY .width // 7
95+ label_day .y = 80
8496pyportal .splash .append (label_day )
8597
8698# Set up label for the time
87- label_time = label .Label (font_small , color = 0x538ab1 , max_glyphs = 200 )
99+ label_time = label .Label (font_small , color = LABEL_TIME_COLOR , max_glyphs = 200 )
88100label_time .x = board .DISPLAY .width // 4
89101label_time .y = 150
90102pyportal .splash .append (label_time )
@@ -97,22 +109,20 @@ def wday_to_weekday_name(tm_wday):
97109 print ("Getting new time from internet..." )
98110 pyportal .get_local_time (secrets ['timezone' ])
99111 refresh_time = time .monotonic ()
112+ # set the_time
113+ the_time = time .localtime ()
114+ # Convert tm_wday to name of day
115+ weekday = wday_to_weekday_name (the_time .tm_wday )
100116 except (ValueError , RuntimeError ) as error :
101117 print ("Failed to get data, retrying\n " , e )
102118 wifi .reset ()
103119 continue
104120
105- # set the_time
106- the_time = time .localtime ()
107-
108- # Convert tm_wday to name of day
109- weekday = wday_to_weekday_name (the_time .tm_wday )
110-
111121 # set the day label's text
112122 label_day .text = weekday
113123
114124 # set the time label's text
115125 label_time .text = "({})" .format (time_name [the_time .tm_hour ])
116126
117- # update every 30s .
118- time .sleep (30 )
127+ # update every minute .
128+ time .sleep (60 )
0 commit comments