1313# Create the RTC instance:
1414rtc = adafruit_ds3231 .DS3231 (i2c )
1515
16+ # Set up Feather M4 onboard LED for output
1617LED13 = digitalio .DigitalInOut (board .D13 )
1718LED13 .direction = digitalio .Direction .OUTPUT
1819
20+ # Set digital 6 as an input for slide switch
21+ Slide_Switch = digitalio .DigitalInOut (board .D6 )
22+ Slide_Switch .switch_to_input (pull = digitalio .Pull .UP )
23+
1924pixel_pin = board .D5
2025num_pixels = 21
21- pixels = neopixel .NeoPixel (pixel_pin , num_pixels , brightness = 1.0 )
22- pixels .fill ((0 , 0 , 0 ))
23- COLOR = (0 , 200 , 0 ) # Green
26+ pixels = neopixel .NeoPixel (pixel_pin , num_pixels , brightness = 1.0 ,
27+ auto_write = False )
28+ pixels .fill ((0 , 0 , 0 )) # Blanking Display
29+ COLOR = (0 , 200 , 0 ) # Green for time later in code
2430
2531# Bitmap values for each value. These can be OR'ed together
2632THREE = 1
27- EIGHT = 1 << 1
28- ELEVEN = 1 << 2
29- TWO = 1 << 3
30- SIX = 1 << 4
31- FOUR = 1 << 5
32- SEVEN = 1 << 6
33- NOON = 1 << 7
34- TEN = 1 << 8
35- ONE = 1 << 9
36- FIVE = 1 << 10
37- MIDNIGHT = 1 << 11
38- NINE = 1 << 12
39- PAST = 1 << 13
40- TO = 1 << 14
41- FIVEMIN = 1 << 15
42- QUARTER = 1 << 16
43- TENMIN = 1 << 17
44- HALF = 1 << 18
45- TWENTY = 1 << 19
33+ EIGHT = 1 << 1
34+ ELEVEN = 1 << 2
35+ TWO = 1 << 3
36+ SIX = 1 << 4
37+ FOUR = 1 << 5
38+ SEVEN = 1 << 6
39+ NOON = 1 << 7
40+ TEN = 1 << 8
41+ ONE = 1 << 9
42+ FIVE = 1 << 10
43+ MIDNIGHT = 1 << 11
44+ NINE = 1 << 12
45+ PAST = 1 << 13
46+ TO = 1 << 14
47+ FIVEMIN = 1 << 15
48+ QUARTER = 1 << 16
49+ TENMIN = 1 << 17
50+ HALF = 1 << 18
51+ TWENTY = 1 << 19
4652
4753# Pass in hour and minute, return LED bitmask
4854# pylint: disable=too-many-branches
@@ -118,17 +124,24 @@ def writetime(the_hr, the_min):
118124
119125# Main loop
120126LEDstate = 0
121- FirstLoop = True
127+ Write_Now = True
122128
123129while True :
124130 t = rtc .datetime
125131 # print("The date is {} {}/{}/{}".format(days[int(t.tm_wday)],
126132 # t.tm_mday, t.tm_mon, t.tm_year))
127133 # print("The time is {}:{:02}:{:02}".format(t.tm_hour, t.tm_min, t.tm_sec))
128134 hour = t .tm_hour
135+ if not Slide_Switch .value : # Slide switch activate = Daylight savings
136+ # print("Switch detected for daylight savings")
137+ if hour == 24 :
138+ hour = 1
139+ else :
140+ hour += 1
141+ Write_Now = True # Trigger a write
129142 minute = t .tm_min
130143 second = t .tm_sec
131- if second == 59 or FirstLoop :
144+ if second == 59 or Write_Now :
132145 # print("The time is {}:{:02}".format(t.tm_hour, t.tm_min))
133146 pixels .fill ((0 , 0 , 0 )) # blank all pixels for change
134147 the_time = writetime (hour , minute )
@@ -142,5 +155,5 @@ def writetime(the_hr, the_min):
142155 else :
143156 LED13 .value = False
144157 LEDstate = 0
145- Firstloop = False
158+ Write_Now = False
146159 time .sleep (1 ) # wait a second
0 commit comments