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 
64 #if defined(__GNUC__) && __GNUC__ >= 7
65 #define VEML7700_FALLTHROUGH __attribute__((fallthrough));
66 #else
67 #define VEML7700_FALLTHROUGH
68 #endif
69 
71 typedef enum {
72  VEML_LUX_NORMAL,
73  VEML_LUX_CORRECTED,
74  VEML_LUX_AUTO,
75  VEML_LUX_NORMAL_NOWAIT,
76  VEML_LUX_CORRECTED_NOWAIT
77 } luxMethod;
78 
84 public:
86  bool begin(TwoWire *theWire = &Wire);
87 
88  void enable(bool enable);
89  bool enabled(void);
90 
91  void interruptEnable(bool enable);
92  bool interruptEnabled(void);
93  void setPersistence(uint8_t pers);
94  uint8_t getPersistence(void);
95  void setIntegrationTime(uint8_t it, bool wait = true);
96  uint8_t getIntegrationTime(void);
97  int getIntegrationTimeValue(void);
98  void setGain(uint8_t gain);
99  uint8_t getGain(void);
100  float getGainValue(void);
101  void powerSaveEnable(bool enable);
102  bool powerSaveEnabled(void);
103  void setPowerSaveMode(uint8_t mode);
104  uint8_t getPowerSaveMode(void);
105 
106  void setLowThreshold(uint16_t value);
107  uint16_t getLowThreshold(void);
108  void setHighThreshold(uint16_t value);
109  uint16_t getHighThreshold(void);
110  uint16_t interruptStatus(void);
111 
112  uint16_t readALS(bool wait = false);
113  uint16_t readWhite(bool wait = false);
114  float readLux(luxMethod method = VEML_LUX_NORMAL);
115 
116 private:
117  const float MAX_RES = 0.0036;
118  const float GAIN_MAX = 2;
119  const float IT_MAX = 800;
120  float getResolution(void);
121  float computeLux(uint16_t rawALS, bool corrected = false);
122  float autoLux(void);
123  void readWait(void);
124  unsigned long lastRead;
125 
126  Adafruit_I2CRegister *ALS_Config, *ALS_Data, *White_Data, *ALS_HighThreshold,
127  *ALS_LowThreshold, *Power_Saving, *Interrupt_Status;
128  Adafruit_I2CRegisterBits *ALS_Shutdown, *ALS_Interrupt_Enable,
129  *ALS_Persistence, *ALS_Integration_Time, *ALS_Gain, *PowerSave_Enable,
130  *PowerSave_Mode;
131  Adafruit_I2CDevice *i2c_dev;
132 };
133 
134 #endif
bool enabled(void)
Ask if the interrupt is enabled.
Definition: Adafruit_VEML7700.cpp:159
Class that stores state and functions for interacting with VEML7700 Light Sensor. ...
Definition: Adafruit_VEML7700.h:83
uint16_t readWhite(bool wait=false)
Read the raw white light data.
Definition: Adafruit_VEML7700.cpp:131
uint8_t getGain(void)
Get ALS gain setting.
Definition: Adafruit_VEML7700.cpp:261
void setGain(uint8_t gain)
Set ALS gain.
Definition: Adafruit_VEML7700.cpp:251
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:302
bool interruptEnabled(void)
Ask if the interrupt is enabled.
Definition: Adafruit_VEML7700.cpp:173
void setPersistence(uint8_t pers)
Set the ALS IRQ persistence setting.
Definition: Adafruit_VEML7700.cpp:182
int getIntegrationTimeValue(void)
Get ALS integration time value.
Definition: Adafruit_VEML7700.cpp:227
luxMethod
Definition: Adafruit_VEML7700.h:71
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 persistence setting.
Definition: Adafruit_VEML7700.cpp:191
uint8_t getPowerSaveMode(void)
Retrieve the power save register data.
Definition: Adafruit_VEML7700.cpp:310
void setIntegrationTime(uint8_t it, bool wait=true)
Set ALS integration time.
Definition: Adafruit_VEML7700.cpp:203
void enable(bool enable)
Enable or disable the sensor.
Definition: Adafruit_VEML7700.cpp:142
void powerSaveEnable(bool enable)
Enable power save mode.
Definition: Adafruit_VEML7700.cpp:286
uint8_t getIntegrationTime(void)
Get ALS integration time setting.
Definition: Adafruit_VEML7700.cpp:219
uint16_t interruptStatus(void)
Retrieve the interrupt status register data.
Definition: Adafruit_VEML7700.cpp:350
void setHighThreshold(uint16_t value)
Assign the high threshold register data.
Definition: Adafruit_VEML7700.cpp:334
void setLowThreshold(uint16_t value)
Assign the low threshold register data.
Definition: Adafruit_VEML7700.cpp:318
uint16_t getHighThreshold(void)
Retrieve the high threshold register data.
Definition: Adafruit_VEML7700.cpp:342
void interruptEnable(bool enable)
Enable or disable the interrupt.
Definition: Adafruit_VEML7700.cpp:165
uint16_t getLowThreshold(void)
Retrieve the low threshold register data.
Definition: Adafruit_VEML7700.cpp:326
float getGainValue(void)
Get ALS gain value.
Definition: Adafruit_VEML7700.cpp:267
bool powerSaveEnabled(void)
Check if power save mode is enabled.
Definition: Adafruit_VEML7700.cpp:294
uint16_t readALS(bool wait=false)
Read the raw ALS data.
Definition: Adafruit_VEML7700.cpp:117