Skip to content

Commit d9f10ce

Browse files
author
jposada202020
committed
adding_displayio_example
1 parent 42125bf commit d9f10ce

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

docs/examples.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/mmc56x3_simpletest.py
77
:caption: examples/mmc56x3_simpletest.py
88
:linenos:
9+
10+
Continuous mode test
11+
--------------------
12+
Test using continuous mode.
13+
14+
.. literalinclude:: ../examples/mmc56x3_continuous.py
15+
:caption: examples/mmc56x3_continuoust.py
16+
:linenos:
17+
18+
DisplayIO Simpletest
19+
---------------------
20+
21+
This is a simple test for boards with built-in display.
22+
23+
.. literalinclude:: ../examples/mmc56x3_displayio_simpletest.py
24+
:caption: examples/mmc56x3_displayio_simpletest.py
25+
:linenos:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2024 Jose D. Montoya
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
import time
7+
8+
import board
9+
from adafruit_display_text.bitmap_label import Label
10+
from displayio import Group
11+
from terminalio import FONT
12+
13+
import adafruit_mmc56x3
14+
15+
# Simple demo of using the built-in display.
16+
# create a main_group to hold anything we want to show on the display.
17+
main_group = Group()
18+
# Initialize I2C bus and sensor.
19+
i2c = board.I2C() # uses board.SCL and board.SDA
20+
sensor = adafruit_mmc56x3.MMC5603(i2c)
21+
22+
# Create Label(s) to show the readings. If you have a very small
23+
# display you may need to change to scale=1.
24+
display_output_label = Label(FONT, text="", scale=2)
25+
26+
# place the label(s) in the middle of the screen with anchored positioning
27+
display_output_label.anchor_point = (0, 0)
28+
display_output_label.anchored_position = (
29+
4,
30+
board.DISPLAY.height // 2 - 60,
31+
)
32+
33+
# add the label(s) to the main_group
34+
main_group.append(display_output_label)
35+
36+
# set the main_group as the root_group of the built-in DISPLAY
37+
board.DISPLAY.root_group = main_group
38+
39+
# begin main loop
40+
while True:
41+
# update the text of the label(s) to show the sensor readings
42+
mag_x, mag_y, mag_z = sensor.magnetic
43+
display_output_label.text = (
44+
f"Acceleration\n"
45+
+ f"x: {mag_x:.1f} uT\n"
46+
+ f"y: {mag_y:.1f} uT\n"
47+
+ f"z: {mag_z:.1f} uT"
48+
)
49+
# wait for a bit
50+
time.sleep(0.5)

0 commit comments

Comments
 (0)