Skip to content

Commit 48dc546

Browse files
authored
Merge pull request #34 from jposada202020/adding_displayio_example
adding_displayio_example
2 parents 1924936 + ce17bf2 commit 48dc546

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

docs/examples.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,39 @@ Demo
44
.. literalinclude:: ../examples/pcf8523_simpletest.py
55
:caption: examples/pcf8523_simpletest.py
66
:linenos:
7+
8+
Square wave generation
9+
-----------------------
10+
11+
Simple demo for clockout-mode (square-wave generation)
12+
13+
.. literalinclude:: ../examples/pcf8523_clockout.py
14+
:caption: examples/pcf8523_clockout.py
15+
:linenos:
16+
17+
Timer Flag Operation
18+
-----------------------
19+
20+
Simple demo for timer operation using the timer-flag
21+
22+
.. literalinclude:: ../examples/pcf8523_timer_flag.py
23+
:caption: examples/pcf8523_timer_flag.py
24+
:linenos:
25+
26+
Timer Interrupt
27+
-----------------------
28+
29+
Simple demo for timer operation, using the interrupt-pin
30+
31+
.. literalinclude:: ../examples/pcf8523_timer_interrupt.py
32+
:caption: examples/pcf8523_timer_interrupt.py
33+
:linenos:
34+
35+
DisplayIO Simpletest
36+
---------------------
37+
38+
This is a simple test for boards with built-in display.
39+
40+
.. literalinclude:: ../examples/pcf8523_displayio_simpletest.py
41+
:caption: examples/pcf8523_displayio_simpletest.py
42+
:linenos:
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
# Simple demo of the PCF8523 real-time clock using a built-in display.
7+
import time
8+
import board
9+
from adafruit_display_text.bitmap_label import Label
10+
from terminalio import FONT
11+
from displayio import Group
12+
from adafruit_pcf8523.pcf8523 import PCF8523
13+
14+
15+
# create a main_group to hold anything we want to show on the display.
16+
main_group = Group()
17+
# Initialize I2C bus and sensor.
18+
i2c = board.I2C() # uses board.SCL and board.SDA
19+
rtc = PCF8523(i2c)
20+
21+
# Lookup table for names of days (nicer printing).
22+
days = (
23+
"Monday",
24+
"Tuesday",
25+
"Wednesday",
26+
"Thursday",
27+
"Friday",
28+
"Saturday",
29+
"Sunday",
30+
)
31+
32+
# Set the time
33+
t = time.struct_time((2024, 12, 12, 10, 31, 0, 0, -1, -1))
34+
rtc.datetime = t
35+
print("Setting time to:", t)
36+
37+
# Create two Labels to show the readings. If you have a very small
38+
# display you may need to change to scale=1.
39+
date_output_label = Label(FONT, text="", scale=2)
40+
time_output_label = Label(FONT, text="", scale=2)
41+
42+
# place the label in the middle of the screen with anchored positioning
43+
date_output_label.anchor_point = (0, 0)
44+
date_output_label.anchored_position = (4, board.DISPLAY.height // 2)
45+
time_output_label.anchor_point = (0, 0)
46+
time_output_label.anchored_position = (4, 20 + board.DISPLAY.height // 2)
47+
48+
# add the label to the main_group
49+
main_group.append(date_output_label)
50+
main_group.append(time_output_label)
51+
52+
# set the main_group as the root_group of the built-in DISPLAY
53+
board.DISPLAY.root_group = main_group
54+
55+
# begin main loop
56+
while True:
57+
# Update the label.text property to change the text on the display
58+
t = rtc.datetime
59+
date_output_label.text = (
60+
f"The date is {days[int(t.tm_wday)]} {t.tm_mday}/{t.tm_mon}/{t.tm_year}"
61+
)
62+
time_output_label.text = f"The time is {t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}"
63+
# wait for a bit
64+
time.sleep(1)

0 commit comments

Comments
 (0)