Skip to content

Commit 5a7d5f8

Browse files
author
caternuson
committed
docs
1 parent 1bd8bd5 commit 5a7d5f8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Introduction
1010
:target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
1111
:alt: Gitter
1212
13-
TODO
13+
CircuitPython driver for TSL2561 Light Sensor.
1414

1515
Dependencies
1616
=============
@@ -26,7 +26,13 @@ This is easily achieved by downloading
2626
Usage Example
2727
=============
2828

29-
TODO
29+
.. code-block:: python
30+
31+
>>> import adafruit_tsl2561
32+
>>> tsl = adafruit_tsl2561.TSL2561()
33+
>>> tsl.enabled = True
34+
>>> tsl.light
35+
3294.37
3036
3137
Contributing
3238
============

adafruit_tsl2561.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
TSL2561_GAIN_SCALE = (16, 1)
4646
TSL2561_TIME_SCALE = (1 / 0.034, 1 / 0.252, 1)
47+
TSL2561_CLIP_THRESHOLD = (4900, 37000, 65000)
4748

4849
class TSL2561():
4950
"""Class which provides interface to TSL2561 light sensor."""
@@ -67,7 +68,7 @@ def id(self):
6768
@property
6869
def enabled(self):
6970
"""The state of the sensor."""
70-
return self._read_register(TSL2561_REGISTER_CONTROL) & 0x03
71+
return bool(self._read_register(TSL2561_REGISTER_CONTROL) & 0x03)
7172

7273
@enabled.setter
7374
def enabled(self, enable):
@@ -134,6 +135,8 @@ def _compute_lux(self):
134135
"""Based on datasheet for FN package."""
135136
ch0, ch1 = self.luminosity
136137
if ch0 == 0: return 0
138+
if ch0 > TSL2561_CLIP_THRESHOLD[self.integration_time]: return 0
139+
if ch1 > TSL2561_CLIP_THRESHOLD[self.integration_time]: return 0
137140
ratio = ch1 / ch0
138141
if ratio > 0 and ratio <= 0.50:
139142
lux = 0.0304 * ch0 - 0.062 * ch0 * ratio**1.4

0 commit comments

Comments
 (0)