Skip to content

Commit f3d5a52

Browse files
committed
Add displayio example
1 parent 7b99df2 commit f3d5a52

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: 2024
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
from adafruit_display_text.label import Label
6+
from displayio import Group
7+
from terminalio import FONT
8+
9+
import adafruit_ds3231
10+
11+
# Create the RTC object, communicating over the board's default I2C bus
12+
i2c = board.I2C() # uses board.SCL and board.SDA
13+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector
14+
ds3231 = adafruit_ds3231.DS3231(i2c)
15+
16+
17+
# Example written for boards with built-in displays
18+
display = board.DISPLAY
19+
20+
# Create a main_group to hold anything we want to show on the display.
21+
main_group = Group()
22+
23+
# Create a Label to show the readings. If you have a very small
24+
# display you may need to change to scale=1.
25+
display_output_label = Label(FONT, text="", scale=2)
26+
27+
# Place the label near the top left corner with anchored positioning
28+
display_output_label.anchor_point = (0, 0)
29+
display_output_label.anchored_position = (4, 4)
30+
31+
# Add the label to the main_group
32+
main_group.append(display_output_label)
33+
34+
# Set the main_group as the root_group of the display
35+
display.root_group = main_group
36+
37+
38+
# Lookup tables for names of days and months - pretty printing
39+
days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
40+
"Saturday", "Sunday")
41+
months = ("January", "February", "March", "April", "May", "June",
42+
"July", "August", "September", "October", "November", "December")
43+
44+
# Begin main loop
45+
while True:
46+
t = ds3231.datetime
47+
# Update the label.text property to change the text on the display
48+
display_output_label.text = f"{days[t.tm_wday]}\
49+
\n{t.tm_mday} {months[t.tm_mon]} {t.tm_year}\
50+
\n{t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}"

0 commit comments

Comments
 (0)