VCNL4010  v1.1.0
Arduino Library for VCNL4010
VCNL4010 Class Reference

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
 

Detailed Description

Main class definition.

Constructor & Destructor Documentation

◆ VCNL4010()

VCNL4010::VCNL4010 ( )

Class constructor

Class Constructor for VCNL4010 instantiates the class. Unused

◆ ~VCNL4010()

VCNL4010::~VCNL4010 ( )

Class destructor

Class Destructor for VCNL4010 destroys the class. Unused

Member Function Documentation

◆ begin() [1/4]

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

◆ begin() [2/4]

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

Parameters
[in]deviceAddressI2C device address
Returns
"true" when device has been detected, otherwise false

◆ begin() [3/4]

bool VCNL4010::begin ( const uint32_t &  i2CSpeed)

Starts the I2C communications with the VCNL4010 (overloaded)

Uses the default VCNL4010_I2C_ADDRESS address specified

Parameters
[in]i2CSpeedSpeed of the I2C bus in Herz
Returns
"true" when device has been detected, otherwise false

◆ begin() [4/4]

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.

Parameters
[in]deviceAddressI2C device address
[in]i2CSpeedSpeed of the I2C bus in Herz
Returns
"true" when device has been detected, otherwise false

◆ clearInterrupt()

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

Parameters
[in]intValUse the 4 lsb bit to set the interrupt values

◆ getAmbientLight()

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.

Returns
unsigned integer 16 measurement value

◆ getInterrupt()

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

Returns
unsigned integer 8, only 4 LSB bits are set

◆ getProximity()

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.

Returns
unsigned integer 16 measurement value

◆ readByte()

uint8_t VCNL4010::readByte ( const uint8_t  addr) const

reads 1 byte from the specified address

Delays VCNL4010_I2C_MS_DELAY after reading

Parameters
[in]addrAddress of the I2C device
Returns
single unsigned integer value with the byte value read from I2C

◆ readWord()

uint16_t VCNL4010::readWord ( const uint8_t  addr) const

reads 2 bytes from the specified address

Delays VCNL4010_I2C_MS_DELAY after reading

Parameters
[in]addrAddress of the I2C device
Returns
Unsigned integer 16 value with the 2 bytes read from I2C

◆ setAmbientContinuous()

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.

Parameters
[in]ContinuousMode"true" for continuous mode, "false" for triggered measurements

◆ setAmbientLight()

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

Parameters
[in]sampleSamples to take per second
[in]avgAverages to take per reading (0-128, rounded to nearest correct value)

◆ setInterrupt()

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

Parameters
[in]count
[in]ProxReady
[in]ALSReady
[in]ProxThreshold
[in]ALSThreshold
[in]lowThreshold
[in]highThreshold

◆ setLEDmA()

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

Parameters
[in]mAMilliamps

◆ setProximityContinuous()

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.

Parameters
[in]ContinuousMode"true" for continuous mode, "false" for triggered measurements

◆ setProximityFreq()

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

Parameters
[in]value0-3 see details for encoded values

◆ setProximityHz()

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)

Parameters
[in]HzHerz code value, described in details

◆ writeByte()

void VCNL4010::writeByte ( const uint8_t  addr,
const uint8_t  data 
) const

Write 1 byte to the specified address

Parameters
[in]addrAddress of the I2C device
[in]dataSingle byte to write

The documentation for this class was generated from the following files: