Adafruit LTR-329 and LTR-303 Light Sensors Library
Adafruit_LTR329_LTR303.h
Go to the documentation of this file.
1 
18 #ifndef _ADAFRUIT_LTR329_LTR303_H
19 #define _ADAFRUIT_LTR329_LTR303_H
20 
21 #include "Arduino.h"
22 #include <Adafruit_I2CDevice.h>
23 #include <Adafruit_I2CRegister.h>
24 #include <Wire.h>
25 
26 #define LTR329_I2CADDR_DEFAULT 0x29
27 #define LTR329_PART_ID 0x86
28 #define LTR329_MANU_ID 0x87
29 #define LTR329_ALS_CTRL 0x80
30 #define LTR329_STATUS 0x8C
31 #define LTR329_CH1DATA 0x88
32 #define LTR329_MEAS_RATE 0x85
33 
34 // These registers on LTR-303 only!
35 #define LTR303_REG_INTERRUPT 0x8F
36 #define LTR303_REG_THRESHHIGH_LSB 0x97
37 #define LTR303_REG_THRESHLOW_LSB 0x99
38 #define LTR303_REG_INTPERSIST 0x9E
39 
40 
41 typedef enum {
42  LTR3XX_GAIN_1 = 0,
43  LTR3XX_GAIN_2 = 1,
44  LTR3XX_GAIN_4 = 2,
45  LTR3XX_GAIN_8 = 3,
46  // 4 & 5 unused!
47  LTR3XX_GAIN_48 = 6,
48  LTR3XX_GAIN_96 = 7,
50 
52 typedef enum {
53  LTR3XX_INTEGTIME_100,
54  LTR3XX_INTEGTIME_50,
55  LTR3XX_INTEGTIME_200,
56  LTR3XX_INTEGTIME_400,
57  LTR3XX_INTEGTIME_150,
58  LTR3XX_INTEGTIME_250,
59  LTR3XX_INTEGTIME_300,
60  LTR3XX_INTEGTIME_350,
62 
64 typedef enum {
65  LTR3XX_MEASRATE_50,
66  LTR3XX_MEASRATE_100,
67  LTR3XX_MEASRATE_200,
68  LTR3XX_MEASRATE_500,
69  LTR3XX_MEASRATE_1000,
70  LTR3XX_MEASRATE_2000,
72 
78 public:
80  bool begin(TwoWire *theWire = &Wire);
81  bool reset(void);
82 
83  void enable(bool en);
84  bool enabled(void);
85 
86  void setGain(ltr329_gain_t gain);
87  ltr329_gain_t getGain(void);
88 
91 
94 
95  bool newDataAvailable(void);
96  bool readBothChannels(uint16_t &ch0, uint16_t &ch1);
97 
98 protected:
99  Adafruit_I2CDevice *i2c_dev = NULL;
100 
101 private:
102  Adafruit_I2CRegister *StatusReg = NULL;
103  Adafruit_I2CRegisterBits *DataReadyBit = NULL;
104  Adafruit_I2CRegisterBits *DataInvalidBit = NULL;
105 };
106 
112 public:
113  Adafruit_LTR303();
114 
115  void enableInterrupt(bool en);
116  void setInterruptPolarity(bool pol);
117 
118  void setLowThreshold(uint16_t value);
119  uint16_t getLowThreshold(void);
120 
121  void setHighThreshold(uint16_t value);
122  uint16_t getHighThreshold(void);
123 
124  void setIntPersistance(uint8_t counts);
125  uint8_t getIntPersistance(void);
126 };
127 
128 #endif
Adafruit_I2CDevice * i2c_dev
The underlying I2C interface.
Definition: Adafruit_LTR329_LTR303.h:99
Adafruit_LTR329()
Instantiates a new LTR329 class.
Definition: Adafruit_LTR329_LTR303.cpp:37
ltr329_integrationtime_t
Integration times, in milliseconds.
Definition: Adafruit_LTR329_LTR303.h:52
ltr329_integrationtime_t getIntegrationTime(void)
Get the sensor&#39;s integration time for light sensing.
Definition: Adafruit_LTR329_LTR303.cpp:178
bool begin(TwoWire *theWire=&Wire)
Setups the hardware for talking to the LTR329.
Definition: Adafruit_LTR329_LTR303.cpp:49
void setIntegrationTime(ltr329_integrationtime_t inttime)
Set the sensor integration time. Longer times are more sensitive but take longer to read! ...
Definition: Adafruit_LTR329_LTR303.cpp:162
bool reset(void)
Perform a soft reset with 10ms delay.
Definition: Adafruit_LTR329_LTR303.cpp:92
ltr329_gain_t getGain(void)
Get the sensor&#39;s gain.
Definition: Adafruit_LTR329_LTR303.cpp:146
ltr329_measurerate_t getMeasurementRate(void)
Get the sensor&#39;s measurement rate.
Definition: Adafruit_LTR329_LTR303.cpp:209
void setMeasurementRate(ltr329_measurerate_t rate)
Set the sensor measurement rate. Longer times are needed when the integration time is longer OR if yo...
Definition: Adafruit_LTR329_LTR303.cpp:194
Class that stores state and functions for interacting with LTR329 Light Sensor.
Definition: Adafruit_LTR329_LTR303.h:77
void setGain(ltr329_gain_t gain)
Set the sensor gain.
Definition: Adafruit_LTR329_LTR303.cpp:133
ltr329_measurerate_t
Measurement rates, in milliseconds.
Definition: Adafruit_LTR329_LTR303.h:64
ltr329_gain_t
Sensor gain for ALS.
Definition: Adafruit_LTR329_LTR303.h:41
bool readBothChannels(uint16_t &ch0, uint16_t &ch1)
Read both 16-bit channels at once, and place data into argument pointers.
Definition: Adafruit_LTR329_LTR303.cpp:231
bool newDataAvailable(void)
Checks if new data is available in data register.
Definition: Adafruit_LTR329_LTR303.cpp:222
bool enabled(void)
Read the enabled-bit from the sensor.
Definition: Adafruit_LTR329_LTR303.cpp:120
void enable(bool en)
Enable or disable the light sensor.
Definition: Adafruit_LTR329_LTR303.cpp:108
Class that stores state and functions for interacting with LTR303 Light Sensor.
Definition: Adafruit_LTR329_LTR303.h:111