Skip to content

Commit ef1e0b3

Browse files
authored
Merge pull request #44 from jposada202020/adding_displayio_example
adding_displayio_example
2 parents bb540bf + 93d1bb2 commit ef1e0b3

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-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/tcs34725_simpletest.py
77
:caption: examples/tcs34725_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/tcs34725_simpletest.py
16+
:caption: examples/tcs34725_simpletest.py
17+
:linenos:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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_tcs34725
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_tcs34725.TCS34725(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+
color_output_label = Label(FONT, text="", scale=2)
23+
temperature_output_label = Label(FONT, text="", scale=2)
24+
lux_output_label = Label(FONT, text="", scale=2)
25+
26+
# place the label(s) in the middle of the screen with anchored positioning
27+
color_output_label.anchor_point = (0, 0)
28+
color_output_label.anchored_position = (
29+
4,
30+
board.DISPLAY.height // 2 - 60,
31+
)
32+
temperature_output_label.anchor_point = (0, 0)
33+
temperature_output_label.anchored_position = (
34+
4,
35+
board.DISPLAY.height // 2 - 0,
36+
)
37+
lux_output_label.anchor_point = (0, 0)
38+
lux_output_label.anchored_position = (
39+
4,
40+
board.DISPLAY.height // 2 + 20,
41+
)
42+
43+
# add the labels to the main_group
44+
main_group.append(color_output_label)
45+
main_group.append(temperature_output_label)
46+
main_group.append(lux_output_label)
47+
48+
# set the main_group as the root_group of the built-in DISPLAY
49+
board.DISPLAY.root_group = main_group
50+
51+
# begin main loop
52+
while True:
53+
# Raw data from the sensor in a 4-tuple of red, green, blue, clear light component values
54+
color_output_label.text = f"RGB color 3-tuple:\n{sensor.color_rgb_bytes}"
55+
# Read the color temperature and lux of the sensor too.
56+
temperature_output_label.text = f"Temp: {sensor.color_temperature}K"
57+
lux_output_label.text = f"Lux: {sensor.lux}"
58+
# wait for a bit
59+
time.sleep(0.5)

0 commit comments

Comments
 (0)