Skip to content

Commit bedcd78

Browse files
authored
Merge pull request #40 from jposada202020/adding_displayIO_example
adding_displayIO_example
2 parents 75acb16 + 866eee3 commit bedcd78

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

docs/examples.rst

+27
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,30 @@ Copy "../examples/vl53l0x_multiple_sensors.py" to your "CIRCUITPY" drive, then r
1515
.. literalinclude:: ../examples/vl53l0x_multiple_sensors.py
1616
:caption: examples/vl53l0x_multiple_sensors.py
1717
:linenos:
18+
19+
Continuous mode
20+
----------------
21+
22+
Simple demo of the VL53L0X distance sensor with continuous mode.
23+
24+
.. literalinclude:: ../examples/vl53l0x_simplecontinuous.py
25+
:caption: examples/vl53l0x_simplecontinuous.py
26+
:linenos:
27+
28+
Multiple VL53L0X on Same I2C Bus and with continuous mode
29+
-----------------------------------------------------------
30+
31+
Example of how to change the assigned address of multiple VL53L0X sensors on the same I2C bus and use
32+
33+
.. literalinclude:: ../examples/vl53l0x_multiple_sensors_continuous.py
34+
:caption: examples/vl53l0x_multiple_sensors_continuous.py
35+
:linenos:
36+
37+
DisplayIO Simpletest
38+
---------------------
39+
40+
This is a simple test for boards with built-in display.
41+
42+
.. literalinclude:: ../examples/vl53l0x_displayio_simpletest.py
43+
:caption: examples/vl53l0x_displayio_simpletest.py
44+
:linenos:
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 VL53L0X distance 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_vl53l0x
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+
vl53 = adafruit_vl53l0x.VL53L0X(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+
display_output_label.text = f"Range: {vl53.range}mm"
39+
# wait for a bit
40+
time.sleep(1.0)

0 commit comments

Comments
 (0)