APDS-9301 Sensor Hookup Guide
Library Overview
Here's a list of the most critical functions supported by the library.
begin(address)
- enables the IC, sets the gain and integration times to minimum (i.e., lowest sensitivity), and disables the interrupt.setGain(gainLevel)
- there are two possible parameters to pass to this function:APDS9301::LOW_GAIN
andAPDS9301::HIGH_GAIN
. High gain is 16x more sensitive than low gain.gain getGain()
- returns one of the two values specified insetGain()
above. This function actually reads the gain from the sensor and returns the true value currently being used.setIntegrationTime(integrationTime)
- there are three possible parameters to pass to this function:APDS9301::INT_TIME_13_7_MS
,APDS9301::INT_TIME_101_MS
, andAPDS9301::INT_TIME_402_MS
. Sensitivity to light increases with integration time, and the rate at which new data is generated by the sensor is also determined by integration time. By default, the integration time is set to the lowest value (13.7ms).intTime getIntegrationTime()
- returns one of the three values specfied insetIntegrationTime()
above. This function actually reads the gain from the sensor and returns the true value currently being used.enableInterrupt(intMode)
- pass eitherAPDS9301::INT_ON
orAPDS9301::INT_OFF
to this function to enable or disable the interrupt functionality. By default, the interrupt is disabled. If enabled, the following three functions will determine the circumstances under which an interrupt will be issued and the INT pin will be set high.setCyclesForInterrupt(cycles)
- sets number of ADC cycles values must be in interrupt range for an interrupt to occur. Pass0
to interrupt on every ADC cycle (ADC cycle time is defined by integration time as discussed above). Pass1
to interrupt if the reading is ever above the high threshold or below the low threshold (see next two functions for information regarding threshold settings). Pass2
through15
to require that many cycles above or below the respective threshold before issuing an interrupt.setLowThreshold(threshold)
- pass anunsigned int
to this function between0
and65535
. Readings on CH0 of the sensor (which detects both visible and IR light) below this threshold for the time set by thesetCyclesForInterrupt()
will trigger an interrupt on the INT pin. To disable the low threshold, simply write0
to this function.unsigned int getLowThreshold()
- returns the current low threshold setting, read from the sensor directly.setHighThreshold(threshold)
- pass anunsigned int
to this function between0
and65535
. Readings on CH0 of the sensor (which detects both visible and IR light) above this threshold for the time set by thesetCyclesForInterrupt()
will trigger an interrupt on the INT pin. To disable the high threshold, simply write65535
to this function.unsigned int getHighThreshold()
- returns the current low threshold setting, read from the sensor directly.float readLuxLevel()
- returns a floating point number representing the current light level in lux. Note that due to inherent inaccuracy in the sensor, this value is only accurate to within 35%-40% of the actual absolute lux value.