Adafruit TSL2561 Arduino Library
Public Member Functions | List of all members
Adafruit_TSL2561_Unified Class Reference

Class that stores state and functions for interacting with TSL2561 Light Sensor. More...

#include <Adafruit_TSL2561_U.h>

Inheritance diagram for Adafruit_TSL2561_Unified:

Public Member Functions

 Adafruit_TSL2561_Unified (uint8_t addr, int32_t sensorID=-1)
 Constructor. More...
 
boolean begin (void)
 Initializes I2C and configures the sensor with default Wire I2C (call this function before doing anything else) More...
 
boolean begin (TwoWire *theWire)
 Initializes I2C and configures the sensor with provided I2C device (call this function before doing anything else) More...
 
boolean init ()
 Initializes I2C connection and settings. Attempts to determine if the sensor is contactable, then sets up a default integration time and gain. Then powers down the chip. More...
 
void enableAutoRange (bool enable)
 Enables or disables the auto-gain settings when reading data from the sensor. More...
 
void setIntegrationTime (tsl2561IntegrationTime_t time)
 Sets the integration time for the TSL2561. Higher time means more light captured (better for low light conditions) but will take longer to run readings. More...
 
void setGain (tsl2561Gain_t gain)
 Adjusts the gain on the TSL2561 (adjusts the sensitivity to light) More...
 
void getLuminosity (uint16_t *broadband, uint16_t *ir)
 Gets the broadband (mixed lighting) and IR only values from the TSL2561, adjusting gain if auto-gain is enabled. More...
 
uint32_t calculateLux (uint16_t broadband, uint16_t ir)
 Converts the raw sensor values to the standard SI lux equivalent. More...
 
bool getEvent (sensors_event_t *)
 Gets the most recent sensor event. More...
 
void getSensor (sensor_t *)
 Gets the sensor_t data. More...
 

Detailed Description

Class that stores state and functions for interacting with TSL2561 Light Sensor.

Constructor & Destructor Documentation

◆ Adafruit_TSL2561_Unified()

Adafruit_TSL2561_Unified::Adafruit_TSL2561_Unified ( uint8_t  addr,
int32_t  sensorID = -1 
)

Constructor.

Parameters
addrThe I2C address this chip can be found on, 0x29, 0x39 or 0x49
sensorIDAn optional ID that will be placed in sensor events to help keep track if you have many sensors in use

Member Function Documentation

◆ begin() [1/2]

boolean Adafruit_TSL2561_Unified::begin ( void  )

Initializes I2C and configures the sensor with default Wire I2C (call this function before doing anything else)

Returns
True if sensor is found and initialized, false otherwise.

◆ begin() [2/2]

boolean Adafruit_TSL2561_Unified::begin ( TwoWire *  theWire)

Initializes I2C and configures the sensor with provided I2C device (call this function before doing anything else)

Parameters
theWireA pointer to any I2C interface (e.g. &Wire1)
Returns
True if sensor is found and initialized, false otherwise.

◆ init()

boolean Adafruit_TSL2561_Unified::init ( )

Initializes I2C connection and settings. Attempts to determine if the sensor is contactable, then sets up a default integration time and gain. Then powers down the chip.

Returns
True if sensor is found and initialized, false otherwise.

◆ enableAutoRange()

void Adafruit_TSL2561_Unified::enableAutoRange ( bool  enable)

Enables or disables the auto-gain settings when reading data from the sensor.

Parameters
enableSet to true to enable, False to disable

◆ setIntegrationTime()

void Adafruit_TSL2561_Unified::setIntegrationTime ( tsl2561IntegrationTime_t  time)

Sets the integration time for the TSL2561. Higher time means more light captured (better for low light conditions) but will take longer to run readings.

Parameters
timeThe amount of time we'd like to add up values

◆ setGain()

void Adafruit_TSL2561_Unified::setGain ( tsl2561Gain_t  gain)

Adjusts the gain on the TSL2561 (adjusts the sensitivity to light)

Parameters
gainThe value we'd like to set the gain to

◆ getLuminosity()

void Adafruit_TSL2561_Unified::getLuminosity ( uint16_t *  broadband,
uint16_t *  ir 
)

Gets the broadband (mixed lighting) and IR only values from the TSL2561, adjusting gain if auto-gain is enabled.

Parameters
broadbandPointer to a uint16_t we will fill with a sensor reading from the IR+visible light diode.
irPointer to a uint16_t we will fill with a sensor the IR-only light diode.

◆ calculateLux()

uint32_t Adafruit_TSL2561_Unified::calculateLux ( uint16_t  broadband,
uint16_t  ir 
)

Converts the raw sensor values to the standard SI lux equivalent.

Parameters
broadbandThe 16-bit sensor reading from the IR+visible light diode.
irThe 16-bit sensor reading from the IR-only light diode.
Returns
The integer Lux value we calcuated. Returns 0 if the sensor is saturated and the values are unreliable, or 65536 if the sensor is saturated.

Returns

◆ getEvent()

bool Adafruit_TSL2561_Unified::getEvent ( sensors_event_t *  event)

Gets the most recent sensor event.

Parameters
eventPointer to a sensor_event_t type that will be filled with the lux value, timestamp, data type and sensor ID.
Returns
True if sensor reading is between 0 and 65535 lux, false if sensor is saturated

◆ getSensor()

void Adafruit_TSL2561_Unified::getSensor ( sensor_t *  sensor)

Gets the sensor_t data.

Parameters
sensorA pointer to a sensor_t structure that we will fill with details about the TSL2561 and its capabilities

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