Adafruit VEML7700 Lux Sensor Library
Adafruit_VEML7700.h
Go to the documentation of this file.
1 
17 #ifndef _ADAFRUIT_VEML7700_H
18 #define _ADAFRUIT_VEML7700_H
19 
20 #include "Arduino.h"
21 #include <Adafruit_I2CDevice.h>
22 #include <Adafruit_I2CRegister.h>
23 #include <Wire.h>
24 
25 #define VEML7700_I2CADDR_DEFAULT 0x10
26 
27 #define VEML7700_ALS_CONFIG 0x00
28 #define VEML7700_ALS_THREHOLD_HIGH 0x01
29 #define VEML7700_ALS_THREHOLD_LOW 0x02
30 #define VEML7700_ALS_POWER_SAVE 0x03
31 #define VEML7700_ALS_DATA 0x04
32 #define VEML7700_WHITE_DATA 0x05
33 #define VEML7700_INTERRUPTSTATUS 0x06
34 
35 #define VEML7700_INTERRUPT_HIGH 0x4000
36 #define VEML7700_INTERRUPT_LOW 0x8000
37 
38 #define VEML7700_GAIN_1 0x00
39 #define VEML7700_GAIN_2 0x01
40 #define VEML7700_GAIN_1_8 0x02
41 #define VEML7700_GAIN_1_4 0x03
42 
43 #define VEML7700_IT_100MS 0x00
44 #define VEML7700_IT_200MS 0x01
45 #define VEML7700_IT_400MS 0x02
46 #define VEML7700_IT_800MS 0x03
47 #define VEML7700_IT_50MS 0x08
48 #define VEML7700_IT_25MS 0x0C
49 
50 #define VEML7700_PERS_1 0x00
51 #define VEML7700_PERS_2 0x01
52 #define VEML7700_PERS_4 0x02
53 #define VEML7700_PERS_8 0x03
54 
55 #define VEML7700_POWERSAVE_MODE1 0x00
56 #define VEML7700_POWERSAVE_MODE2 0x01
57 #define VEML7700_POWERSAVE_MODE3 0x02
58 #define VEML7700_POWERSAVE_MODE4 0x03
59 
60 
61 typedef enum {
62  VEML_LUX_NORMAL,
63  VEML_LUX_CORRECTED,
64  VEML_LUX_AUTO,
65  VEML_LUX_NORMAL_NOWAIT,
66  VEML_LUX_CORRECTED_NOWAIT
67 } luxMethod;
68 
74 public:
76  bool begin(TwoWire *theWire = &Wire);
77 
78  void enable(bool enable);
79  bool enabled(void);
80 
81  void interruptEnable(bool enable);
82  bool interruptEnabled(void);
83  void setPersistence(uint8_t pers);
84  uint8_t getPersistence(void);
85  void setIntegrationTime(uint8_t it, bool wait = true);
86  uint8_t getIntegrationTime(void);
87  int getIntegrationTimeValue(void);
88  void setGain(uint8_t gain);
89  uint8_t getGain(void);
90  float getGainValue(void);
91  void powerSaveEnable(bool enable);
92  bool powerSaveEnabled(void);
93  void setPowerSaveMode(uint8_t mode);
94  uint8_t getPowerSaveMode(void);
95 
96  void setLowThreshold(uint16_t value);
97  uint16_t getLowThreshold(void);
98  void setHighThreshold(uint16_t value);
99  uint16_t getHighThreshold(void);
100  uint16_t interruptStatus(void);
101 
102  uint16_t readALS(bool wait = false);
103  uint16_t readWhite(bool wait = false);
104  float readLux(luxMethod method = VEML_LUX_NORMAL);
105 
106 private:
107  const float MAX_RES = 0.0036;
108  const float GAIN_MAX = 2;
109  const float IT_MAX = 800;
110  float getResolution(void);
111  float computeLux(uint16_t rawALS, bool corrected = false);
112  float autoLux(void);
113  void readWait(void);
114  unsigned long lastRead;
115 
116  Adafruit_I2CRegister *ALS_Config, *ALS_Data, *White_Data, *ALS_HighThreshold,
117  *ALS_LowThreshold, *Power_Saving, *Interrupt_Status;
118  Adafruit_I2CRegisterBits *ALS_Shutdown, *ALS_Interrupt_Enable,
119  *ALS_Persistence, *ALS_Integration_Time, *ALS_Gain, *PowerSave_Enable,
120  *PowerSave_Mode;
121  Adafruit_I2CDevice *i2c_dev;
122 };
123 
124 #endif
bool enabled(void)
Ask if the interrupt is enabled.
Definition: Adafruit_VEML7700.cpp:157
Class that stores state and functions for interacting with VEML7700 Light Sensor. ...
Definition: Adafruit_VEML7700.h:73
uint16_t readWhite(bool wait=false)
Read the raw white light data.
Definition: Adafruit_VEML7700.cpp:129
uint8_t getGain(void)
Get ALS gain setting.
Definition: Adafruit_VEML7700.cpp:259
void setGain(uint8_t gain)
Set ALS gain.
Definition: Adafruit_VEML7700.cpp:249
bool begin(TwoWire *theWire=&Wire)
Sets up the hardware for talking to the VEML7700.
Definition: Adafruit_VEML7700.cpp:42
void setPowerSaveMode(uint8_t mode)
Assign the power save register data.
Definition: Adafruit_VEML7700.cpp:300
bool interruptEnabled(void)
Ask if the interrupt is enabled.
Definition: Adafruit_VEML7700.cpp:171
void setPersistence(uint8_t pers)
Set the ALS IRQ persistance setting.
Definition: Adafruit_VEML7700.cpp:180
int getIntegrationTimeValue(void)
Get ALS integration time value.
Definition: Adafruit_VEML7700.cpp:225
luxMethod
Definition: Adafruit_VEML7700.h:61
float readLux(luxMethod method=VEML_LUX_NORMAL)
Read the calibrated lux value. See app note lux table on page 5.
Definition: Adafruit_VEML7700.cpp:90
Adafruit_VEML7700()
Instantiates a new VEML7700 class.
Definition: Adafruit_VEML7700.cpp:35
uint8_t getPersistence(void)
Get the ALS IRQ persistance setting.
Definition: Adafruit_VEML7700.cpp:189
uint8_t getPowerSaveMode(void)
Retrieve the power save register data.
Definition: Adafruit_VEML7700.cpp:308
void setIntegrationTime(uint8_t it, bool wait=true)
Set ALS integration time.
Definition: Adafruit_VEML7700.cpp:201
void enable(bool enable)
Enable or disable the sensor.
Definition: Adafruit_VEML7700.cpp:140
void powerSaveEnable(bool enable)
Enable power save mode.
Definition: Adafruit_VEML7700.cpp:284
uint8_t getIntegrationTime(void)
Get ALS integration time setting.
Definition: Adafruit_VEML7700.cpp:217
uint16_t interruptStatus(void)
Retrieve the interrupt status register data.
Definition: Adafruit_VEML7700.cpp:348
void setHighThreshold(uint16_t value)
Assign the high threshold register data.
Definition: Adafruit_VEML7700.cpp:332
void setLowThreshold(uint16_t value)
Assign the low threshold register data.
Definition: Adafruit_VEML7700.cpp:316
uint16_t getHighThreshold(void)
Retrieve the high threshold register data.
Definition: Adafruit_VEML7700.cpp:340
void interruptEnable(bool enable)
Enable or disable the interrupt.
Definition: Adafruit_VEML7700.cpp:163
uint16_t getLowThreshold(void)
Retrieve the low threshold register data.
Definition: Adafruit_VEML7700.cpp:324
float getGainValue(void)
Get ALS gain value.
Definition: Adafruit_VEML7700.cpp:265
bool powerSaveEnabled(void)
Check if power save mode is enabled.
Definition: Adafruit_VEML7700.cpp:292
uint16_t readALS(bool wait=false)
Read the raw ALS data.
Definition: Adafruit_VEML7700.cpp:115