Adafruit VCNL4040 Arduino Library
Adafruit_VCNL4040.h
Go to the documentation of this file.
1 
17 #ifndef _ADAFRUIT_VCNL4040_H
18 #define _ADAFRUIT_VCNL4040_H
19 
20 #include "Arduino.h"
21 #include <Adafruit_BusIO_Register.h>
22 #include <Adafruit_I2CDevice.h>
23 #include <Wire.h>
24 
25 #define VCNL4040_I2CADDR_DEFAULT 0x60
26 
27 // All addresses are for 16bit registers;
28 // duplicates are for high or low bytes that aren't used together
29 #define VCNL4040_ALS_CONFIG \
30  0x00
31 #define VCNL4040_ALS_THDH 0x01
32 #define VCNL4040_ALS_THDL 0x02
33 #define VCNL4040_PS_CONF1_L \
34  0x03
35 #define VCNL4040_PS_MS_H 0x04
36 #define VCNL4040_PS_THDL 0x06
37 #define VCNL4040_PS_THDH 0x07
38 #define VCNL4040_PS_DATA 0x08
39 #define VCNL4040_ALS_DATA 0x09
40 #define VCNL4040_WHITE_DATA 0x0A
41 #define VCNL4040_INT_FLAG 0x0B
42 #define VCNL4040_DEVICE_ID 0x0C
43 
44 
49 typedef enum led_current {
50  VCNL4040_LED_CURRENT_50MA,
51  VCNL4040_LED_CURRENT_75MA,
52  VCNL4040_LED_CURRENT_100MA,
53  VCNL4040_LED_CURRENT_120MA,
54  VCNL4040_LED_CURRENT_140MA,
55  VCNL4040_LED_CURRENT_160MA,
56  VCNL4040_LED_CURRENT_180MA,
57  VCNL4040_LED_CURRENT_200MA,
59 
65 typedef enum led_duty_cycle {
66  VCNL4040_LED_DUTY_1_40,
67  VCNL4040_LED_DUTY_1_80,
68  VCNL4040_LED_DUTY_1_160,
69  VCNL4040_LED_DUTY_1_320,
71 
78  VCNL4040_AMBIENT_INTEGRATION_TIME_80MS,
79  VCNL4040_AMBIENT_INTEGRATION_TIME_160MS,
80  VCNL4040_AMBIENT_INTEGRATION_TIME_320MS,
81  VCNL4040_AMBIENT_INTEGRATION_TIME_640MS,
83 
90  VCNL4040_PROXIMITY_INTEGRATION_TIME_1T,
91  VCNL4040_PROXIMITY_INTEGRATION_TIME_1_5T,
92  VCNL4040_PROXIMITY_INTEGRATION_TIME_2T,
93  VCNL4040_PROXIMITY_INTEGRATION_TIME_2_5T,
94  VCNL4040_PROXIMITY_INTEGRATION_TIME_3T,
95  VCNL4040_PROXIMITY_INTEGRATION_TIME_3_5T,
96  VCNL4040_PROXIMITY_INTEGRATION_TIME_4T,
97  VCNL4040_PROXIMITY_INTEGRATION_TIME_8T,
104 typedef enum proximity_type {
105  VCNL4040_PROXIMITY_INT_DISABLE,
106  VCNL4040_PROXIMITY_INT_CLOSE,
107  VCNL4040_PROXIMITY_INT_AWAY,
108  VCNL4040_PROXIMITY_INT_CLOSE_AWAY,
110 
116 typedef enum interrupt_type {
117  VCNL4040_PROXIMITY_AWAY,
118  VCNL4040_PROXIMITY_CLOSE,
119  VCNL4040_AMBIENT_HIGH = 4,
120  VCNL4040_AMBIENT_LOW,
122 
128 public:
130  boolean begin(uint8_t i2c_addr = VCNL4040_I2CADDR_DEFAULT,
131  TwoWire *wire = &Wire);
132  uint16_t getProximity(void);
133  uint16_t getAmbientLight(void);
134  uint16_t getWhiteLight(void);
135  uint16_t getLux(void);
136 
137  void enableProximity(bool enable);
138  void enableAmbientLight(bool enable);
139  void enableWhiteLight(bool enable);
140 
141  uint8_t getInterruptStatus(void);
142  void enableAmbientLightInterrupts(bool enable);
143 
144  uint16_t getAmbientLightHighThreshold(void);
145  void setAmbientLightHighThreshold(uint16_t high_threshold);
146 
147  uint16_t getAmbientLightLowThreshold(void);
148  void setAmbientLightLowThreshold(uint16_t low_threshold);
149 
150  void enableProximityInterrupts(VCNL4040_ProximityType interrupt_condition);
151 
152  uint16_t getProximityLowThreshold(void);
153  void setProximityLowThreshold(uint16_t low_threshold);
154 
155  uint16_t getProximityHighThreshold(void);
156  void setProximityHighThreshold(uint16_t high_threshold);
157 
159  void
161 
164 
167 
170 
171  bool getProximityHighResolution(void);
172  void setProximityHighResolution(bool high_resolution);
173 
174  Adafruit_BusIO_Register
176  *ALS_CONFIG,
177  *PS_MS;
178 
179 private:
180  bool _init(void);
181 
182  Adafruit_I2CDevice *i2c_dev;
183 };
184 
185 #endif
uint16_t getWhiteLight(void)
Gets the current white light value.
Definition: Adafruit_VCNL4040.cpp:114
uint16_t getLux(void)
Gets the current ambient light sensor in Lux.
Definition: Adafruit_VCNL4040.cpp:131
void setProximityLEDDutyCycle(VCNL4040_LEDDutyCycle duty_cycle)
Sets the duty cycle for the LED used for proximity measurements.
Definition: Adafruit_VCNL4040.cpp:434
Adafruit_VCNL4040()
Instantiates a new VCNL4040 class.
Definition: Adafruit_VCNL4040.cpp:43
enum proximity_type VCNL4040_ProximityType
Proximity interrupt types.
enum led_current VCNL4040_LEDCurrent
Proximity LED current values.
Adafruit_BusIO_Register * PS_CONFIG_12
BusIO Register for PS_CONFIG1 and PS_CONFIG2.
Definition: Adafruit_VCNL4040.h:175
void enableWhiteLight(bool enable)
Enables white light measurements.
Definition: Adafruit_VCNL4040.cpp:172
void setProximityLEDCurrent(VCNL4040_LEDCurrent led_current)
Sets the current for the LED used for proximity measurements.
Definition: Adafruit_VCNL4040.cpp:410
#define VCNL4040_I2CADDR_DEFAULT
VCNL4040 default i2c address.
Definition: Adafruit_VCNL4040.h:25
void enableProximityInterrupts(VCNL4040_ProximityType interrupt_condition)
Disables or enables proximity interrupts under a given condition.
Definition: Adafruit_VCNL4040.cpp:272
VCNL4040_LEDCurrent getProximityLEDCurrent(void)
Gets the current for the LED used for proximity measurements.
Definition: Adafruit_VCNL4040.cpp:399
Adafruit_BusIO_Register * PS_MS
BusIO Register for PS_MS.
Definition: Adafruit_VCNL4040.h:175
void setProximityHighThreshold(uint16_t high_threshold)
Sets the proximity high threshold.
Definition: Adafruit_VCNL4040.cpp:324
void setProximityHighResolution(bool high_resolution)
Sets the resolution of proximity measurements.
Definition: Adafruit_VCNL4040.cpp:460
bool getProximityHighResolution(void)
Gets the resolution of proximity measurements.
Definition: Adafruit_VCNL4040.cpp:448
void setAmbientIntegrationTime(VCNL4040_AmbientIntegration integration_time)
Sets the integration time for ambient light sensing measurements.
Definition: Adafruit_VCNL4040.cpp:379
enum led_duty_cycle VCNL4040_LEDDutyCycle
Proximity LED duty cycle values.
Adafruit_BusIO_Register * ALS_CONFIG
BusIO Register for ALS_CONFIG.
Definition: Adafruit_VCNL4040.h:175
ambient_integration_time
Ambient light integration time values.
Definition: Adafruit_VCNL4040.h:77
enum ambient_integration_time VCNL4040_AmbientIntegration
Ambient light integration time values.
void setAmbientLightLowThreshold(uint16_t low_threshold)
Sets the ambient light low threshold.
Definition: Adafruit_VCNL4040.cpp:255
proximity_type
Proximity interrupt types.
Definition: Adafruit_VCNL4040.h:104
interrupt_type
Interrupt types.
Definition: Adafruit_VCNL4040.h:116
VCNL4040_LEDDutyCycle getProximityLEDDutyCycle(void)
Sets the duty cycle for the LED used for proximity measurements.
Definition: Adafruit_VCNL4040.cpp:422
proximity_integration_time
Proximity measurement integration time values.
Definition: Adafruit_VCNL4040.h:89
enum interrupt_type VCNL4040_InterruptType
Interrupt types.
void enableAmbientLightInterrupts(bool enable)
Enables or disables ambient light based interrupts.
Definition: Adafruit_VCNL4040.cpp:207
uint16_t getProximity(void)
Gets the current proximity sensor value.
Definition: Adafruit_VCNL4040.cpp:90
void enableProximity(bool enable)
Enables or disables proximity measurements.
Definition: Adafruit_VCNL4040.cpp:148
uint16_t getAmbientLight(void)
Gets the current ambient light sensor value.
Definition: Adafruit_VCNL4040.cpp:103
uint16_t getProximityLowThreshold(void)
Gets the proximity low threshold.
Definition: Adafruit_VCNL4040.cpp:286
led_current
Proximity LED current values.
Definition: Adafruit_VCNL4040.h:49
uint16_t getAmbientLightLowThreshold(void)
Gets the ambient light low threshold.
Definition: Adafruit_VCNL4040.cpp:242
uint16_t getProximityHighThreshold(void)
Gets the proximity high threshold.
Definition: Adafruit_VCNL4040.cpp:311
void setAmbientLightHighThreshold(uint16_t high_threshold)
Sets the ambient light high threshold.
Definition: Adafruit_VCNL4040.cpp:231
Class that stores state and functions for interacting with the VCNL4040 I2C Digital Potentiometer...
Definition: Adafruit_VCNL4040.h:127
VCNL4040_ProximityIntegration getProximityIntegrationTime(void)
Gets the integration time for proximity sensing measurements.
Definition: Adafruit_VCNL4040.cpp:339
led_duty_cycle
Proximity LED duty cycle values.
Definition: Adafruit_VCNL4040.h:65
uint16_t getAmbientLightHighThreshold(void)
Gets the current ambient light high threshold.
Definition: Adafruit_VCNL4040.cpp:219
void setProximityLowThreshold(uint16_t low_threshold)
Sets the proximity low threshold.
Definition: Adafruit_VCNL4040.cpp:299
enum proximity_integration_time VCNL4040_ProximityIntegration
Proximity measurement integration time values.
uint8_t getInterruptStatus(void)
Gets and clears the interrupt status register.
Definition: Adafruit_VCNL4040.cpp:189
VCNL4040_AmbientIntegration getAmbientIntegrationTime(void)
Gets the integration time for ambient light sensing measurements.
Definition: Adafruit_VCNL4040.cpp:365
boolean begin(uint8_t i2c_addr=VCNL4040_I2CADDR_DEFAULT, TwoWire *wire=&Wire)
Sets up the hardware and initializes I2C.
Definition: Adafruit_VCNL4040.cpp:53
void enableAmbientLight(bool enable)
Enables ambient light measurements.
Definition: Adafruit_VCNL4040.cpp:160
void setProximityIntegrationTime(VCNL4040_ProximityIntegration integration_time)
Sets the integration time for proximity sensing measurements.
Definition: Adafruit_VCNL4040.cpp:352