weatherstation/firmware/sensor_apds9960.ino
Florian Eitel be334245ff
Refactor sensor interface with extra files and function pointer
That makes it easier to enable/disable sensors.

Also added support for APDS9930
2019-08-04 12:53:20 +02:00

27 lines
732 B
C++

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