Datasheet

Unified Sensor API
The Adafruit_TSL2591 library makes use of the Adafruit unified sensor framework to provide sensor data in a
standardized format and scale. If you wish to make use of this framweork, the two key functions that you need to work
with are getEvent and getSensor, as described below:
void getEvent(sensors_event_t*)
This function will read a single sample from the sensor and return it in a generic sensors_event_t object. To use this
function, you simply pass in a sensors_event_t reference, which will be populated by the function, and then read the
/**************************************************************************/
/*
Configures the gain and integration time for the TSL2561
*/
/**************************************************************************/
void configureSensor(void)
{
// You can change the gain on the fly, to adapt to brighter/dimmer light situations
//tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
tsl.setGain(TSL2591_GAIN_MED); // 25x gain
//tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
// Changing the integration time gives you a longer time over which to sense light
// longer timelines are slower, but are good in very low light situtations!
tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
//tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
//tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
//tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
//tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
//tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
/* Display the gain and integration time for reference sake */
Serial.println("------------------------------------");
Serial.print ("Gain: ");
tsl2591Gain_t gain = tsl.getGain();
switch(gain)
{
case TSL2591_GAIN_LOW:
Serial.println("1x (Low)");
break;
case TSL2591_GAIN_MED:
Serial.println("25x (Medium)");
break;
case TSL2591_GAIN_HIGH:
Serial.println("428x (High)");
break;
case TSL2591_GAIN_MAX:
Serial.println("9876x (Max)");
break;
}
Serial.print ("Timing: ");
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(" ms");
Serial.println("------------------------------------");
Serial.println("");
}
© Adafruit Industries https://learn.adafruit.com/adafruit-tsl2591 Page 15 of 24