Skip to content

Commit 43e7a87

Browse files
authored
Merge pull request #11 from jerryneedell/jerryn_fixlux
revise lux calculation to accept 0 reading without error
2 parents cdb6d71 + 127ec4c commit 43e7a87

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

adafruit_tsl2561.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ def _compute_lux(self):
148148
if ch1 > _CLIP_THRESHOLD[self.integration_time]:
149149
return None
150150
ratio = ch1 / ch0
151-
if ratio > 0 and ratio <= 0.50:
151+
if ratio >= 0 and ratio <= 0.50:
152152
lux = 0.0304 * ch0 - 0.062 * ch0 * ratio**1.4
153-
elif ratio > 0.50 and ratio <= 0.61:
153+
elif ratio <= 0.61:
154154
lux = 0.0224 * ch0 - 0.031 * ch1
155-
elif ratio > 0.61 and ratio <= 0.80:
155+
elif ratio <= 0.80:
156156
lux = 0.0128 * ch0 - 0.0153 * ch1
157-
elif ratio > 0.80 and ratio <= 1.30:
157+
elif ratio <= 1.30:
158158
lux = 0.00146 * ch0 - 0.00112 * ch1
159-
elif ratio > 1.30:
159+
else:
160160
lux = 0
161161
# Pretty sure the floating point math formula on pg. 23 of datasheet
162162
# is based on 16x gain and 402ms integration time. Need to scale

0 commit comments

Comments
 (0)