Here is the first sketch: a simple clock.
# SPDX-FileCopyrightText: Copyright (c) 2024 Randall Bohn (dexter)
#
# SPDX-License-Identifier: MIT
#
# EQUIPMENT
## Adafruit Feather ESP32-S2 TFT
## CircuitPython 9.0.0 or 8.2.9
## FeatherWing Doubler https://www.adafruit.com/product/2890
import board
import displayio
import time
from adafruit_bitmap_font.bitmap_font import load_font
from adafruit_display_text.label import Label
from adafruit_display_shapes.circle import Circle
import wifi
from socketpool import SocketPool
from adafruit_ntp import NTP
import rtc
display = board.DISPLAY
pool = SocketPool(wifi.radio)
ntp = NTP(pool, tz_offset=-7.0) # US/Denver
rtc.RTC().datetime = ntp.datetime
def get_time():
now = time.localtime()
a = f"{now.tm_year}-{now.tm_mon:02d}-{now.tm_mday:02d} "
hour = now.tm_hour % 12
if hour == 0: hour = 12
b= f"{hour:02d}:{now.tm_min:02d}:{now.tm_sec:02d}"
return a,b
radius = 24
splash = displayio.Group()
cc = Circle(display.width*7//8, display.height//2, radius, outline=0xFFFFFF)
splash.append(cc)
font = load_font("/fonts/Arial-18.pcf")
clock = Label(font, text="----",
color=0xFFFF66,
x=display.width//8,
y=display.height*7//8)
splash.append(clock)
display.root_group=splash
def loop():
clock.text = get_time()[1]
time.sleep(0.1)
if __name__=="__main__":
while True:
loop()
I found the Arial-18 font here: MagTag Google Calendar
This page (Desktop Multifunction Device: Clock) was last updated on November 19, 2024.
Text editor powered by tinymce.