2019-08-04 11:56:18 +02:00
|
|
|
#include <Adafruit_APDS9960.h> // Adafruit APDS9960 - https://www.makerfabs.com/index.php?route=product/product&product_id=281
|
|
|
|
|
|
|
|
Adafruit_APDS9960 _sensor_apds9960;
|
|
|
|
|
2022-09-14 11:55:43 +02:00
|
|
|
bool sensor_apds9960_begin()
|
|
|
|
{
|
2019-08-04 11:56:18 +02:00
|
|
|
bool status = _sensor_apds9960.begin();
|
2022-09-14 11:55:43 +02:00
|
|
|
|
|
|
|
if (status)
|
|
|
|
{
|
2019-08-04 11:56:18 +02:00
|
|
|
_sensor_apds9960.enableColor(true);
|
|
|
|
debug("APDS9960 Connected");
|
2022-09-14 11:55:43 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
} else {
|
|
|
|
debug("Could not find a valid APDS9960 sensor, check wiring!");
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2022-09-14 11:55:43 +02:00
|
|
|
float apds9960_light()
|
|
|
|
{
|
2019-08-04 11:56:18 +02:00
|
|
|
uint16_t red, green, blue, white, lux;
|
|
|
|
|
2022-09-14 11:55:43 +02:00
|
|
|
while(!_sensor_apds9960.colorDataReady())
|
|
|
|
{
|
2019-08-04 11:56:18 +02:00
|
|
|
delay(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
_sensor_apds9960.getColorData(&red, &green, &blue, &white);
|
2022-09-14 11:55:43 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
//calculate lux
|
|
|
|
lux = _sensor_apds9960.calculateLux(red, green, blue);
|
2022-09-14 11:55:43 +02:00
|
|
|
|
2019-08-04 11:56:18 +02:00
|
|
|
return lux * LIGHT_FACTOR;
|
|
|
|
}
|