Skip to content

Commit aeda46e

Browse files
authored
Merge pull request #26 from jposada202020/adding_displayio_example
adding_displayio_example
2 parents 4050a08 + 837e264 commit aeda46e

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

docs/examples.rst

+9
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/veml6070_simpletest.py
77
:caption: examples/veml6070_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/veml6070_displayio_simpletest.py
16+
:caption: examples/veml6070_displayio_simpletest.py
17+
:linenos:
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 VEML6070 UV sensor 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+
import adafruit_veml6070
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+
uv = adafruit_veml6070.VEML6070(i2c)
20+
21+
# Create a Label to show the readings. If you have a very small
22+
# display you may need to change to scale=1.
23+
display_output_label = Label(FONT, text="", scale=2)
24+
25+
# place the label in the middle of the screen with anchored positioning
26+
display_output_label.anchor_point = (0, 0)
27+
display_output_label.anchored_position = (4, board.DISPLAY.height // 2)
28+
29+
# add the label to the main_group
30+
main_group.append(display_output_label)
31+
32+
# set the main_group as the root_group of the built-in DISPLAY
33+
board.DISPLAY.root_group = main_group
34+
35+
# begin main loop
36+
while True:
37+
# Update the label.text property to change the text on the display
38+
uv_raw = uv.uv_raw
39+
display_output_label.text = (
40+
f"Reading: {uv_raw} Risk Level: {uv.get_index(uv_raw)} lux"
41+
)
42+
# wait for a bit
43+
time.sleep(0.5)

0 commit comments

Comments
 (0)