diff --git a/simpleclock.ino b/simpleclock.ino index 41e980b..5cfdba5 100644 --- a/simpleclock.ino +++ b/simpleclock.ino @@ -49,7 +49,9 @@ volatile bool timeSkewEven = false; // comp. 1 additional second per 2 days /* ambient light compensation aka night mode */ const int photoPin = A2; volatile bool measureAmbLight = true; -unsigned int ambLight = 0; +unsigned int ambLight = 0; // actual value +unsigned int ambLight2 = 0; // previous med. value +unsigned int ambLight3 = 0; // pre-previous med. value unsigned long previousLightTimer = 0; const long refresh_interval = 40; // refresh rate 25Hz @@ -238,6 +240,7 @@ void loop() (previousLightTimer > currentMillis)) { // millis() reset every ~49 days previousLightTimer = currentMillis; ambLight = analogRead(photoPin); + ambLight = (ambLight + ambLight2 + ambLight3) / 3; /* Ambient light compensation * ambLight can be in range of 0..1023, if it 910+, it has point to use @@ -279,6 +282,9 @@ void loop() } else if (ambLight < 100) { Display.setBrightness(-22); } + + ambLight3 = ambLight2; + ambLight2 = ambLight; } Display.refreshDisplay();