From af59615e932499f2068e03bae4d4da88fe9c8479 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 7 Aug 2019 15:53:02 +0200 Subject: [PATCH] auto-adjust lightMeter sensitivity --- src/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2e0d7e9..b6e4bef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -181,6 +181,22 @@ void getSensorMeasurements() { if (light_active) { sensor_readings.lux = lightMeter.readLightLevel(); + // auto-adjust sensitivity + if (sensor_readings.lux < 0) { + Serial.println("Error reading light level"); + } else if (sensor_readings.lux > 40000.0) { + if (lightMeter.setMTreg(32)) { + Serial.println(F("Setting MTReg to low value for high light environment")); + } + } else if (sensor_readings.lux <= 10.0) { + if (lightMeter.setMTreg(138)) { + Serial.println(F("Setting MTReg to high value for low light environment")); + } + } else { // if (sensor_readings.lux > 10.0) + if (lightMeter.setMTreg(69)) { + Serial.println(F("Setting MTReg to default value for normal light environment")); + } + } } if (sds_active) {