File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ Introduction
10
10
:target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
11
11
:alt: Gitter
12
12
13
- TODO
13
+ CircuitPython driver for TSL2561 Light Sensor.
14
14
15
15
Dependencies
16
16
=============
@@ -26,7 +26,13 @@ This is easily achieved by downloading
26
26
Usage Example
27
27
=============
28
28
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
30
36
31
37
Contributing
32
38
============
Original file line number Diff line number Diff line change 44
44
45
45
TSL2561_GAIN_SCALE = (16 , 1 )
46
46
TSL2561_TIME_SCALE = (1 / 0.034 , 1 / 0.252 , 1 )
47
+ TSL2561_CLIP_THRESHOLD = (4900 , 37000 , 65000 )
47
48
48
49
class TSL2561 ():
49
50
"""Class which provides interface to TSL2561 light sensor."""
@@ -67,7 +68,7 @@ def id(self):
67
68
@property
68
69
def enabled (self ):
69
70
"""The state of the sensor."""
70
- return self ._read_register (TSL2561_REGISTER_CONTROL ) & 0x03
71
+ return bool ( self ._read_register (TSL2561_REGISTER_CONTROL ) & 0x03 )
71
72
72
73
@enabled .setter
73
74
def enabled (self , enable ):
@@ -134,6 +135,8 @@ def _compute_lux(self):
134
135
"""Based on datasheet for FN package."""
135
136
ch0 , ch1 = self .luminosity
136
137
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
137
140
ratio = ch1 / ch0
138
141
if ratio > 0 and ratio <= 0.50 :
139
142
lux = 0.0304 * ch0 - 0.062 * ch0 * ratio ** 1.4
You can’t perform that action at this time.
0 commit comments