Skip to content

Commit 9224eeb

Browse files
committed
format update, appease black
1 parent 24aa202 commit 9224eeb

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

examples/adafruit_vl53l1x_displayio_simpletest.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
22
# contributions by J Fletcher, adapting code by Prof Gallaugher:
33
# https://www.youtube.com/watch?v=cdx1A1xoEWc&t=5s
44
# tested on ESP32-S3 Reverse TFT Feather:
@@ -17,7 +17,8 @@
1717

1818
# Create sensor object, communicating over the board's default I2C bus
1919
# i2c = board.I2C() # uses board.SCL and board.SDA
20-
i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
20+
i2c = board.STEMMA_I2C()
21+
# For using the built-in STEMMA QT connector on a microcontroller
2122
vl53 = adafruit_vl53l1x.VL53L1X(i2c)
2223

2324
# Create a Label to show the readings. If you have a very small
@@ -34,7 +35,7 @@
3435
# set the main_group as the root_group of the built-in DISPLAY
3536
board.DISPLAY.root_group = main_group
3637
# create a display object placeholder to be updated by the loop
37-
screen = (f"Distance: {''}cm, {''}in, {''}ft")
38+
screen = f"Distance: {''}cm, {''}in, {''}ft"
3839
# initiate repeated sensor readings
3940
vl53.start_ranging()
4041

@@ -45,19 +46,22 @@
4546
# Assuming the first 'try' succeeds, this will be updated once the loop starts over
4647
display_output_label.text = screen
4748

48-
# This 'try' sequence will either update the displayed items with fresh data or repeat the
49-
# last available data. VL53L1X sensors output `None` when no object reflects the laser,
49+
# This 'try' sequence will either update the displayed items with fresh data or repeat the
50+
# last available data. VL53L1X sensors output `None` when no object reflects the laser,
5051
# e.g., there is nothing within 4 meters, or when objects pass too quickly in and out of
5152
# view (usually perpendicular to the field of vision).
5253
try:
53-
if vl53.distance: # simple test to see there is a value to read; no value = exception
54-
distance = vl53.distance # sets the variable (used by the display) to the sensor data
55-
inches = distance*0.394 # VL53L1X outputs distance in metric, so we convert to imperial
56-
screen = (f"Distance: {distance: .1f}cm, {inches: .1f}in, {inches/12: .1f}ft")
54+
if vl53.distance:
55+
# simple test to see there is a value to read; no value = exception
56+
distance = vl53.distance
57+
# sets the variable (used by the display) to the sensor data
58+
inches = distance * 0.394
59+
# VL53L1X outputs distance in metric, so we convert to imperial
60+
screen = f"Distance: {distance: .1f}cm, {inches: .1f}in, {inches/12: .1f}ft"
5761
# if we made it this far, we have new data to display!
58-
except TypeError:
62+
except TypeError:
5963
repeat_screen = screen
6064
screen = repeat_screen
6165
# if things went sideways, we repeat the previous loop's data so we can try again
62-
66+
6367
time.sleep(0.25)

0 commit comments

Comments
 (0)