Implement simple dim
This commit is contained in:
@@ -49,7 +49,9 @@ volatile bool timeSkewEven = false; // comp. 1 additional second per 2 days
|
|||||||
/* ambient light compensation aka night mode */
|
/* ambient light compensation aka night mode */
|
||||||
const int photoPin = A2;
|
const int photoPin = A2;
|
||||||
volatile bool measureAmbLight = true;
|
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;
|
unsigned long previousLightTimer = 0;
|
||||||
const long refresh_interval = 40; // refresh rate 25Hz
|
const long refresh_interval = 40; // refresh rate 25Hz
|
||||||
|
|
||||||
@@ -238,6 +240,7 @@ void loop()
|
|||||||
(previousLightTimer > currentMillis)) { // millis() reset every ~49 days
|
(previousLightTimer > currentMillis)) { // millis() reset every ~49 days
|
||||||
previousLightTimer = currentMillis;
|
previousLightTimer = currentMillis;
|
||||||
ambLight = analogRead(photoPin);
|
ambLight = analogRead(photoPin);
|
||||||
|
ambLight = (ambLight + ambLight2 + ambLight3) / 3;
|
||||||
|
|
||||||
/* Ambient light compensation
|
/* Ambient light compensation
|
||||||
* ambLight can be in range of 0..1023, if it 910+, it has point to use
|
* 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) {
|
} else if (ambLight < 100) {
|
||||||
Display.setBrightness(-22);
|
Display.setBrightness(-22);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ambLight3 = ambLight2;
|
||||||
|
ambLight2 = ambLight;
|
||||||
}
|
}
|
||||||
|
|
||||||
Display.refreshDisplay();
|
Display.refreshDisplay();
|
||||||
|
|||||||
Reference in New Issue
Block a user