VCNL4010
v1.1.0
Arduino Library for VCNL4010
|
Main class definition. More...
#include <VCNL4010.h>
Public Member Functions | |
VCNL4010 () | |
~VCNL4010 () | |
bool | begin (void) |
bool | begin (const uint8_t deviceAddress) |
bool | begin (const uint32_t &i2CSpeed) |
bool | begin (const uint8_t deviceAddress, const uint32_t &i2CSpeed) |
void | setProximityHz (const uint8_t Hz=2) |
void | setLEDmA (const uint8_t mA=20) const |
void | setProximityFreq (const uint8_t value=0) |
uint16_t | getAmbientLight () const |
uint16_t | getProximity () const |
uint8_t | getInterrupt () const |
void | clearInterrupt (const uint8_t intVal=0) const |
uint8_t | readByte (const uint8_t addr) const |
uint16_t | readWord (const uint8_t addr) const |
void | writeByte (const uint8_t addr, const uint8_t data) const |
void | setAmbientLight (const uint8_t sample=2, const uint8_t avg=32) const |
void | setAmbientContinuous (const bool ContinuousMode=true) |
void | setProximityContinuous (const bool ContinuousMode=true) |
void | setInterrupt (const uint8_t count=1, const bool ProxReady=false, const bool ALSReady=false, const bool ProxThreshold=false, const bool ALSThreshold=false, const uint16_t lowThreshold=0, const uint16_t highThreshold=UINT16_MAX) const |
Main class definition.
VCNL4010::VCNL4010 | ( | ) |
Class constructor
Class Constructor for VCNL4010 instantiates the class. Unused
VCNL4010::~VCNL4010 | ( | ) |
Class destructor
Class Destructor for VCNL4010 destroys the class. Unused
bool VCNL4010::begin | ( | void | ) |
Starts the I2C communications with the VCNL4010 (overloaded)
Uses the default address specified in VCNL4010_I2C_ADDRESS if one is not given and standard I2C Speed
bool VCNL4010::begin | ( | const uint8_t | deviceAddress | ) |
Starts the I2C communications with the VCNL4010 (overloaded)
Uses the address specified defaults to the standard I2C Speed
[in] | deviceAddress | I2C device address |
bool VCNL4010::begin | ( | const uint32_t & | i2CSpeed | ) |
Starts the I2C communications with the VCNL4010 (overloaded)
Uses the default VCNL4010_I2C_ADDRESS address specified
[in] | i2CSpeed | Speed of the I2C bus in Herz |
bool VCNL4010::begin | ( | const uint8_t | deviceAddress, |
const uint32_t & | i2CSpeed | ||
) |
Starts the I2C communications with the VCNL4010 (overloaded)
This is the only overloaded begin() that actually starts the device and initializes the system. The other begin() calls all call this one with the appropraite parameter value set.
[in] | deviceAddress | I2C device address |
[in] | i2CSpeed | Speed of the I2C bus in Herz |
void VCNL4010::clearInterrupt | ( | const uint8_t | intVal = 0 | ) | const |
clearInterrupt() overwrites the 4 bits denoting which, if any, interrupts have been triggered
Bit 3 - proximity interrupt
Bit 2 - ambient light interrupt
Bit 1 - low threshold interrupt
Bit 0 - high threshold interrupt
The bit needs to be written as "1" in order to clear it, so send the bitwise "not" value
[in] | intVal | Use the 4 lsb bit to set the interrupt values |
uint16_t VCNL4010::getAmbientLight | ( | ) | const |
retrieves the 16 bit ambient light value.
Since we always send a request for another reading after retrieving the previous results we just need to wait for a result to come back.
uint8_t VCNL4010::getInterrupt | ( | ) | const |
retrieves the 4 bits denoting which, if any, interrupts have been triggered
Bit 3 - proximity interrupt
Bit 2 - ambient light interrupt
Bit 1 - low threshold interrupt
Bit 0 - high threshold interrupt
uint16_t VCNL4010::getProximity | ( | ) | const |
retrieves the 16 bit proximity value.
Since we always send a request for another reading after retrieving the previous results we just need to wait for a result to come back.
uint8_t VCNL4010::readByte | ( | const uint8_t | addr | ) | const |
reads 1 byte from the specified address
Delays VCNL4010_I2C_MS_DELAY after reading
[in] | addr | Address of the I2C device |
uint16_t VCNL4010::readWord | ( | const uint8_t | addr | ) | const |
reads 2 bytes from the specified address
Delays VCNL4010_I2C_MS_DELAY after reading
[in] | addr | Address of the I2C device |
void VCNL4010::setAmbientContinuous | ( | const bool | ContinuousMode = true | ) |
sets or unsets the continuous measurement mode for the ambient light sensor
There are two COMMAND register bits that neeed to be set for continuous mode, the first is the BIT_SELFTIMED_EN bit which generally enables continuous mode, and the second is the BIT_PROX_EN bit, which turns proximity continuous measurements on. The first bit may not be reset if the other mode remains in continuous.
[in] | ContinuousMode | "true" for continuous mode, "false" for triggered measurements |
void VCNL4010::setAmbientLight | ( | const uint8_t | sample = 2 , |
const uint8_t | avg = 32 |
||
) | const |
Number of samples to take per second and the number of samples averaged for a reading
each reading takes 300microseconds and the default period for a measurement is 100ms
[in] | sample | Samples to take per second |
[in] | avg | Averages to take per reading (0-128, rounded to nearest correct value) |
void VCNL4010::setInterrupt | ( | const uint8_t | count = 1 , |
const bool | ProxReady = false , |
||
const bool | ALSReady = false , |
||
const bool | ProxThreshold = false , |
||
const bool | ALSThreshold = false , |
||
const uint16_t | lowThreshold = 0 , |
||
const uint16_t | highThreshold = UINT16_MAX |
||
) | const |
sets the interrupts used
The count is the number of consecutive readings needed in order to trigger an interrupt for threshold low or high being exceeded. Then a boolean to indicate an interrupt on Proximity reading ready, then the same for an ALS reading to be ready. The next two values indicate whether to trigger an interrupt on threshold low or high value being exceeded for Proximity and ALS. Since only one can be used the ALS is chosen when both are set. Finally the low and high threshold values themselves
[in] | count | |
[in] | ProxReady | |
[in] | ALSReady | |
[in] | ProxThreshold | |
[in] | ALSThreshold | |
[in] | lowThreshold | |
[in] | highThreshold |
void VCNL4010::setLEDmA | ( | const uint8_t | mA = 20 | ) | const |
sets the IR LED current output in milliamps
Range is between 0mA and 200mA, internally set in steps of 10mA with input values being truncated down to the next lower value. No range checking is performed
[in] | mA | Milliamps |
void VCNL4010::setProximityContinuous | ( | const bool | ContinuousMode = true | ) |
Sets or unsets the continuous measurement mode for the proximity sensor
There are two COMMAND register bits that neeed to be set for continuous mode, the first is the BIT_SELFTIMED_EN bit which generally enables continuous mode, and the second is the BIT_PROX_EN bit, which turns proximity continuous measurements on. The first bit may not be reset if the other mode remains in continuous.
[in] | ContinuousMode | "true" for continuous mode, "false" for triggered measurements |
void VCNL4010::setProximityFreq | ( | const uint8_t | value = 0 | ) |
sets the proximity modulator timing to one of 4 possible values
The following 4 values can be set:
00 = 390.625 kHz (DEFAULT)
01 = 781.25 kHz
10 = 1.5625 MHz
11 = 3.125 MHz
[in] | value | 0-3 see details for encoded values |
void VCNL4010::setProximityHz | ( | const uint8_t | Hz = 2 | ) |
set the frequency with which the proximity sensor pulses are sent/read
The only values that the VCNL4010 can be set to are:
Bits | Measurements/S |
---|---|
000 | 1.95 (DEFAULT) |
001 | 3.90625 |
010 | 7.8125 |
011 | 16.625 |
100 | 31.25 |
101 | 62.5 |
110 | 125 |
111 | 250 |
These roughly equate to Hz (2,4,8,16,32,64,128 and 256)
[in] | Hz | Herz code value, described in details |
void VCNL4010::writeByte | ( | const uint8_t | addr, |
const uint8_t | data | ||
) | const |
Write 1 byte to the specified address
[in] | addr | Address of the I2C device |
[in] | data | Single byte to write |