|
| 1 | +# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import time |
| 6 | +import displayio |
| 7 | +import picodvi |
| 8 | +import board |
| 9 | +import framebufferio |
| 10 | +from adafruit_bitmap_font import bitmap_font |
| 11 | +from adafruit_display_text import label |
| 12 | +from adafruit_pcf8523.pcf8523 import PCF8523 |
| 13 | +from adafruit_ticks import ticks_ms, ticks_add, ticks_diff |
| 14 | + |
| 15 | +EVENT_YEAR = 2024 |
| 16 | +EVENT_MONTH = 8 |
| 17 | +EVENT_DAY = 16 |
| 18 | +EVENT_HOUR = 0 |
| 19 | +EVENT_MINUTE = 0 |
| 20 | +# we'll make a python-friendly structure |
| 21 | +event_time = time.struct_time((EVENT_YEAR, EVENT_MONTH, EVENT_DAY, |
| 22 | + EVENT_HOUR, EVENT_MINUTE, 0, # we don't track seconds |
| 23 | + -1, -1, False)) # we dont know day of week/year or DST |
| 24 | + |
| 25 | +# check for DVI Feather with built-in display |
| 26 | +if 'DISPLAY' in dir(board): |
| 27 | + display = board.DISPLAY |
| 28 | + |
| 29 | +# check for DVI feather without built-in display |
| 30 | +elif 'CKP' in dir(board): |
| 31 | + displayio.release_displays() |
| 32 | + fb = picodvi.Framebuffer(320, 240, |
| 33 | + clk_dp=board.CKP, clk_dn=board.CKN, |
| 34 | + red_dp=board.D0P, red_dn=board.D0N, |
| 35 | + green_dp=board.D1P, green_dn=board.D1N, |
| 36 | + blue_dp=board.D2P, blue_dn=board.D2N, |
| 37 | + color_depth=8) |
| 38 | + display = framebufferio.FramebufferDisplay(fb) |
| 39 | +# otherwise assume Pico |
| 40 | +else: |
| 41 | + displayio.release_displays() |
| 42 | + fb = picodvi.Framebuffer(320, 240, |
| 43 | + clk_dp=board.GP12, clk_dn=board.GP13, |
| 44 | + red_dp=board.GP10, red_dn=board.GP11, |
| 45 | + green_dp=board.GP8, green_dn=board.GP9, |
| 46 | + blue_dp=board.GP6, blue_dn=board.GP7, |
| 47 | + color_depth=8) |
| 48 | + display = framebufferio.FramebufferDisplay(fb) |
| 49 | + |
| 50 | +i2c = board.I2C() |
| 51 | +rtc = PCF8523(i2c) |
| 52 | +set_clock = False |
| 53 | +if set_clock: |
| 54 | + # year, mon, date, hour, min, sec, wday, yday, isdst |
| 55 | + t = time.struct_time((2024, 8, 1, 16, 26, 00, 0, -1, -1)) |
| 56 | + print("Setting time to:", t) |
| 57 | + rtc.datetime = t |
| 58 | + print() |
| 59 | +# variable to hold RTC datetime |
| 60 | +t = rtc.datetime |
| 61 | + |
| 62 | +pink = 0xf1078e |
| 63 | +purple = 0x673192 |
| 64 | +aqua = 0x19beed |
| 65 | +group = displayio.Group() |
| 66 | +my_font = bitmap_font.load_font("/Helvetica-Bold-16.pcf") |
| 67 | +clock_area = label.Label(my_font, text="00:00:00:00", color=pink) |
| 68 | +clock_area.anchor_point = (0.0, 1.0) |
| 69 | +clock_area.anchored_position = (display.width / 2 - clock_area.width / 2, |
| 70 | + display.height - (clock_area.height + 20)) |
| 71 | +text1 = label.Label(my_font, text="Starting In:", color=aqua) |
| 72 | +text1.anchor_point = (0.0, 0.0) |
| 73 | +text1.anchored_position = (display.width / 2 - text1.width / 2, |
| 74 | + display.height - (clock_area.height + text1.height + 35)) |
| 75 | + |
| 76 | +blinka_bitmap = displayio.OnDiskBitmap("/cpday_dvi.bmp") |
| 77 | +blinka_grid = displayio.TileGrid(blinka_bitmap, pixel_shader=blinka_bitmap.pixel_shader) |
| 78 | +group.append(blinka_grid) |
| 79 | +group.append(text1) |
| 80 | +group.append(clock_area) |
| 81 | +display.root_group = group |
| 82 | + |
| 83 | +clock_clock = ticks_ms() |
| 84 | +clock_timer = 1000 |
| 85 | +while True: |
| 86 | + if ticks_diff(ticks_ms(), clock_clock) >= clock_timer: |
| 87 | + t = rtc.datetime |
| 88 | + remaining = time.mktime(event_time) - time.mktime(t) |
| 89 | + secs_remaining = remaining % 60 |
| 90 | + remaining //= 60 |
| 91 | + mins_remaining = remaining % 60 |
| 92 | + remaining //= 60 |
| 93 | + hours_remaining = remaining % 24 |
| 94 | + remaining //= 24 |
| 95 | + days_remaining = remaining |
| 96 | + clock_area.text = (f"{days_remaining:0>2}:{hours_remaining:0>2}" + |
| 97 | + f":{mins_remaining:0>2}:{secs_remaining:0>2}") |
| 98 | + clock_clock = ticks_add(clock_clock, clock_timer) |
0 commit comments