Add DST switch capability
Per Limor 7/10
This commit is contained in:
parent
e54f970343
commit
ba8c92b62b
1 changed files with 38 additions and 25 deletions
|
|
@ -13,14 +13,20 @@ i2c = io.I2C(board.SCL, board.SDA)
|
||||||
# Create the RTC instance:
|
# Create the RTC instance:
|
||||||
rtc = adafruit_ds3231.DS3231(i2c)
|
rtc = adafruit_ds3231.DS3231(i2c)
|
||||||
|
|
||||||
|
# Set up Feather M4 onboard LED for output
|
||||||
LED13 = digitalio.DigitalInOut(board.D13)
|
LED13 = digitalio.DigitalInOut(board.D13)
|
||||||
LED13.direction = digitalio.Direction.OUTPUT
|
LED13.direction = digitalio.Direction.OUTPUT
|
||||||
|
|
||||||
|
# Set digital 6 as an input for slide switch
|
||||||
|
Slide_Switch = digitalio.DigitalInOut(board.D6)
|
||||||
|
Slide_Switch.switch_to_input(pull=digitalio.Pull.UP)
|
||||||
|
|
||||||
pixel_pin = board.D5
|
pixel_pin = board.D5
|
||||||
num_pixels = 21
|
num_pixels = 21
|
||||||
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=1.0)
|
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=1.0,
|
||||||
pixels.fill((0, 0, 0))
|
auto_write=False)
|
||||||
COLOR = (0, 200, 0) # Green
|
pixels.fill((0, 0, 0)) # Blanking Display
|
||||||
|
COLOR = (0, 200, 0) # Green for time later in code
|
||||||
|
|
||||||
# Bitmap values for each value. These can be OR'ed together
|
# Bitmap values for each value. These can be OR'ed together
|
||||||
THREE = 1
|
THREE = 1
|
||||||
|
|
@ -118,7 +124,7 @@ def writetime(the_hr, the_min):
|
||||||
|
|
||||||
# Main loop
|
# Main loop
|
||||||
LEDstate = 0
|
LEDstate = 0
|
||||||
FirstLoop = True
|
Write_Now = True
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
t = rtc.datetime
|
t = rtc.datetime
|
||||||
|
|
@ -126,9 +132,16 @@ while True:
|
||||||
# t.tm_mday, t.tm_mon, t.tm_year))
|
# t.tm_mday, t.tm_mon, t.tm_year))
|
||||||
# print("The time is {}:{:02}:{:02}".format(t.tm_hour, t.tm_min, t.tm_sec))
|
# print("The time is {}:{:02}:{:02}".format(t.tm_hour, t.tm_min, t.tm_sec))
|
||||||
hour = t.tm_hour
|
hour = t.tm_hour
|
||||||
|
if not Slide_Switch.value: # Slide switch activate = Daylight savings
|
||||||
|
# print("Switch detected for daylight savings")
|
||||||
|
if hour == 24:
|
||||||
|
hour = 1
|
||||||
|
else:
|
||||||
|
hour += 1
|
||||||
|
Write_Now = True # Trigger a write
|
||||||
minute = t.tm_min
|
minute = t.tm_min
|
||||||
second = t.tm_sec
|
second = t.tm_sec
|
||||||
if second == 59 or FirstLoop:
|
if second == 59 or Write_Now:
|
||||||
# print("The time is {}:{:02}".format(t.tm_hour, t.tm_min))
|
# print("The time is {}:{:02}".format(t.tm_hour, t.tm_min))
|
||||||
pixels.fill((0, 0, 0)) # blank all pixels for change
|
pixels.fill((0, 0, 0)) # blank all pixels for change
|
||||||
the_time = writetime(hour, minute)
|
the_time = writetime(hour, minute)
|
||||||
|
|
@ -142,5 +155,5 @@ while True:
|
||||||
else:
|
else:
|
||||||
LED13.value = False
|
LED13.value = False
|
||||||
LEDstate = 0
|
LEDstate = 0
|
||||||
Firstloop = False
|
Write_Now = False
|
||||||
time.sleep(1) # wait a second
|
time.sleep(1) # wait a second
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue