Skip to content

Commit 72be5c0

Browse files
committed
adding displayio example
1 parent c5a6522 commit 72be5c0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

docs/examples.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ Be alerted when the measured value passes a high or low threshold
2424
.. literalinclude:: ../examples/ltr390_alert_test.py
2525
:caption: examples/ltr390_alert_test.py
2626
:linenos:
27+
28+
DisplayIO Simpletest
29+
---------------------
30+
31+
This is a simple test for boards with built-in display.
32+
33+
.. literalinclude:: ../examples/ltr390_displayio_simpletest.py
34+
:caption: examples/ltr390_displayio_simpletest.py
35+
:linenos:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2025 Jose D. Montoya
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
import time
7+
import board
8+
from adafruit_display_text.bitmap_label import Label
9+
from terminalio import FONT
10+
from displayio import Group
11+
import adafruit_ltr390
12+
13+
# Simple demo of using the built-in display.
14+
# create a main_group to hold anything we want to show on the display.
15+
main_group = Group()
16+
# Initialize I2C bus and sensor.
17+
i2c = board.I2C() # uses board.SCL and board.SDA
18+
ltr = adafruit_ltr390.LTR390(i2c)
19+
20+
21+
# Create Label(s) to show the readings. If you have a very small
22+
# display you may need to change to scale=1.
23+
display_output_light = Label(FONT, text="", scale=2)
24+
display_output_lux = Label(FONT, text="", scale=2)
25+
26+
# place the label(s) in the middle of the screen with anchored positioning
27+
display_output_light.anchor_point = (0, 0)
28+
display_output_light.anchored_position = (
29+
4,
30+
board.DISPLAY.height // 2 - 60,
31+
)
32+
display_output_lux.anchor_point = (0, 0)
33+
display_output_lux.anchored_position = (
34+
4,
35+
board.DISPLAY.height // 2 - 40,
36+
)
37+
38+
# add the label(s) to the main_group
39+
main_group.append(display_output_light)
40+
main_group.append(display_output_lux)
41+
42+
# set the main_group as the root_group of the built-in DISPLAY
43+
board.DISPLAY.root_group = main_group
44+
45+
# begin main loop
46+
while True:
47+
# update the text of the label(s) to show the sensor readings
48+
display_output_light.text = f"Ambient Light: {ltr.light:.2f}"
49+
display_output_lux.text = f"Lux: {ltr.lux:.2f}"
50+
# wait for a bit
51+
time.sleep(0.5)

0 commit comments

Comments
 (0)