Skip to content

Commit 2123490

Browse files
committed
Removed divide-by-zero error when no light is present from example
1 parent 2b763c3 commit 2123490

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/tcs34725_simpletest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
r, g, b = sensor.color_rgb_bytes
1919
print('Detected color: #{0:02X}{1:02X}{2:02X}'.format(r, g, b))
2020
# Read the color temperature and lux of the sensor too.
21-
temp = sensor.temperature
22-
lux = sensor.lux
21+
try:
22+
temp = sensor.temperature
23+
lux = sensor.lux
24+
except ZeroDivisionError:
25+
print("No light to measure")
2326
print('Temperature: {0}K Lux: {1}'.format(temp, lux))
2427
# Delay for a second and repeat.
2528
time.sleep(1.0)

0 commit comments

Comments
 (0)