Skip to content

Commit ddf5087

Browse files
authored
Merge pull request #33 from jposada202020/adding_displayio_example
adding_displayio_example
2 parents c99fb36 + be2d50f commit ddf5087

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/examples.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ Demo of reading the range from the VL6180x distance sensor in different access m
4646
.. literalinclude:: ../examples/vl6180x_performancetest.py
4747
:caption: examples/vl6180x_performancetest.py
4848
:linenos:
49+
50+
DisplayIO Simpletest
51+
---------------------
52+
53+
This is a simple test for boards with built-in display.
54+
55+
.. literalinclude:: ../examples/vl6180x_displayio_simpletest.py
56+
:caption: examples/vl6180x_displayio_simpletest.py
57+
: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+
import board
8+
from adafruit_display_text.bitmap_label import Label
9+
from terminalio import FONT
10+
from displayio import Group
11+
import adafruit_vl6180x
12+
13+
# Simple demo of the vl6180x distance sensor.
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_vl6180x.VL6180X(i2c)
19+
20+
# Create two Labels to show the readings. If you have a very small
21+
# display you may need to change to scale=1.
22+
range_output_label = Label(FONT, text="", scale=2)
23+
light_lux_output_label = Label(FONT, text="", scale=2)
24+
25+
# place the labels in the middle of the screen with anchored positioning
26+
range_output_label.anchor_point = (0, 0)
27+
range_output_label.anchored_position = (
28+
4,
29+
board.DISPLAY.height // 2 - 40,
30+
)
31+
light_lux_output_label.anchor_point = (0, 0)
32+
light_lux_output_label.anchored_position = (4, board.DISPLAY.height // 2)
33+
34+
35+
# add the label to the main_group
36+
main_group.append(range_output_label)
37+
main_group.append(light_lux_output_label)
38+
39+
# set the main_group as the root_group of the built-in DISPLAY
40+
board.DISPLAY.root_group = main_group
41+
42+
# begin main loop
43+
while True:
44+
# Update the label.text property to change the text on the display
45+
range_output_label.text = f"Range:{sensor.range} mm"
46+
light_lux_output_label.text = (
47+
f"Lux:{sensor.read_lux(adafruit_vl6180x.ALS_GAIN_1)} lux"
48+
)
49+
# wait for a bit
50+
time.sleep(1.0)

0 commit comments

Comments
 (0)