weatherstation/firmware/sensor_apds9960.ino

36 lines
750 B
Arduino
Raw Normal View History

#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()
{
bool status = _sensor_apds9960.begin();
2022-09-14 11:55:43 +02:00
if (status)
{
_sensor_apds9960.enableColor(true);
debug("APDS9960 Connected");
2022-09-14 11:55:43 +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()
{
uint16_t red, green, blue, white, lux;
2022-09-14 11:55:43 +02:00
while(!_sensor_apds9960.colorDataReady())
{
delay(5);
}
_sensor_apds9960.getColorData(&red, &green, &blue, &white);
2022-09-14 11:55:43 +02:00
//calculate lux
lux = _sensor_apds9960.calculateLux(red, green, blue);
2022-09-14 11:55:43 +02:00
return lux * LIGHT_FACTOR;
}