Skip to content

Commit c9c07dc

Browse files
authored
Merge pull request #5 from dherrada/master
Fixed ZeroDivisionError that occurs when no light is present.
2 parents 2b763c3 + 3b1324c commit c9c07dc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

examples/tcs34725_simpletest.py

Lines changed: 6 additions & 3 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
23-
print('Temperature: {0}K Lux: {1}'.format(temp, lux))
21+
try:
22+
temp = sensor.temperature
23+
lux = sensor.lux
24+
print('Temperature: {0}K Lux: {1}'.format(temp, lux))
25+
except ZeroDivisionError:
26+
print("No light to measure")
2427
# Delay for a second and repeat.
2528
time.sleep(1.0)

0 commit comments

Comments
 (0)