Skip to content

Commit 0e86fb0

Browse files
authored
Merge pull request #31 from jposada202020/adding_displayio_example
adding_displayio_example
2 parents 8f41109 + fc835f0 commit 0e86fb0

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
@@ -6,3 +6,12 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/tsl2591_simpletest.py
77
:caption: examples/tsl2591_simpletest.py
88
:linenos:
9+
10+
DisplayIO Simpletest
11+
---------------------
12+
13+
This is a simple test for boards with built-in display.
14+
15+
.. literalinclude:: ../examples/tsl2591_displayio_simpletest.py
16+
:caption: examples/tsl2591_displayio_simpletest.py
17+
: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: 2024 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_tsl2591
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+
sensor = adafruit_tsl2591.TSL2591(i2c)
19+
20+
# Create Label(s) to show the readings. If you have a very small
21+
# display you may need to change to scale=1.
22+
light_output_label = Label(FONT, text="", scale=2)
23+
infra_output_label = Label(FONT, text="", scale=2)
24+
25+
# place the label(s) in the middle of the screen with anchored positioning
26+
light_output_label.anchor_point = (0, 0)
27+
light_output_label.anchored_position = (
28+
4,
29+
board.DISPLAY.height // 2 - 60,
30+
)
31+
infra_output_label.anchor_point = (0, 0)
32+
infra_output_label.anchored_position = (
33+
4,
34+
board.DISPLAY.height // 2 - 30,
35+
)
36+
37+
# add the label(s) to the main_group
38+
main_group.append(light_output_label)
39+
main_group.append(infra_output_label)
40+
41+
# set the main_group as the root_group of the built-in DISPLAY
42+
board.DISPLAY.root_group = main_group
43+
44+
# begin main loop
45+
while True:
46+
# update the text of the label(s) to show the sensor readings
47+
# Infrared levels range from 0-65535 (16-bit)
48+
light_output_label.text = f"Total light:{sensor.lux:.1f}lux"
49+
infra_output_label.text = f"Infrared light:{sensor.infrared}"
50+
# wait for a bit
51+
time.sleep(0.5)

0 commit comments

Comments
 (0)