feat: automatic brightness adjustment
This commit is contained in:
parent
5977c7ab98
commit
a077f2e7e7
3 changed files with 32 additions and 5 deletions
13
README.md
13
README.md
|
@ -95,3 +95,16 @@ Leaving...
|
||||||
Hard resetting via RTS pin...
|
Hard resetting via RTS pin...
|
||||||
=================================================== [SUCCESS] Took 23.76 seconds ====================================================
|
=================================================== [SUCCESS] Took 23.76 seconds ====================================================
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Automatic Brightness Adjustment
|
||||||
|
|
||||||
|
You can attach a voltage divider with a photo resistor as pull-down and a regular resistor as pull-up to the ESP's8266 ADC.
|
||||||
|
If you choose to do this, please check the ADC voltage level of your ESP8266 board: While the ADC itself works in the range 0.0V...1.0V, a lot of breakout boards scale that up to 0.0V...3.3V.
|
||||||
|
|
||||||
|
Example with a NodeMCU board:
|
||||||
|
|
||||||
|
![brightness.png][brightness.png]
|
||||||
|
|
||||||
|
You can use the values `ADC_MAX`, `ADC_MIN`, `BRIGHT_MIN` and `BRIGHT_MAX` at the top of the file `esp/src/main.cpp` to fine-tune the sensitivity and thresholds of the auto adjustment.
|
||||||
|
|
||||||
|
If you do not use this feature, and observe some flickering, please short the ADC to GND.
|
||||||
|
|
BIN
brightness.png
Normal file
BIN
brightness.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
|
@ -6,6 +6,11 @@
|
||||||
|
|
||||||
Adafruit_NeoPixel pixels(60, 5, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel pixels(60, 5, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
uint16_t ADC_MAX = 900;
|
||||||
|
uint16_t ADC_MIN = 250;
|
||||||
|
uint8_t ADC_INVERT = 1;
|
||||||
|
uint8_t BRIGHT_MIN = 50;
|
||||||
|
uint8_t BRIGHT_MAX = 255;
|
||||||
|
|
||||||
const char *ssid = put your ssid here;
|
const char *ssid = put your ssid here;
|
||||||
const char *password = put your psk here;
|
const char *password = put your psk here;
|
||||||
|
@ -34,6 +39,15 @@ uint8_t sixtyToPixel(int8_t sixty) {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
uint16_t brightness = analogRead(A0);
|
||||||
|
uint8_t bscale = (uint8_t) (255*(min(max(brightness, ADC_MIN), ADC_MAX) - ADC_MIN) / (ADC_MAX - ADC_MIN));
|
||||||
|
if (ADC_INVERT) {
|
||||||
|
bscale = 255 - bscale;
|
||||||
|
}
|
||||||
|
bscale = min(max(bscale, BRIGHT_MIN), BRIGHT_MAX);
|
||||||
|
Serial.print(brightness);
|
||||||
|
Serial.print(" -> ");
|
||||||
|
Serial.println(bscale);
|
||||||
ntp.update();
|
ntp.update();
|
||||||
Serial.println(ntp.formattedTime("%T"));
|
Serial.println(ntp.formattedTime("%T"));
|
||||||
uint8_t h = sixtyToPixel((ntp.hours() % 12) * 5 + (ntp.minutes() / 12));
|
uint8_t h = sixtyToPixel((ntp.hours() % 12) * 5 + (ntp.minutes() / 12));
|
||||||
|
@ -42,10 +56,10 @@ void loop() {
|
||||||
uint8_t m = sixtyToPixel(ntp.minutes());
|
uint8_t m = sixtyToPixel(ntp.minutes());
|
||||||
uint8_t s = sixtyToPixel(ntp.seconds());
|
uint8_t s = sixtyToPixel(ntp.seconds());
|
||||||
pixels.clear();
|
pixels.clear();
|
||||||
pixels.setPixelColor(hl, pixels.getPixelColor(hl) | 0x00ff0000);
|
pixels.setPixelColor(hl, pixels.getPixelColor(hl) | (bscale << 16));
|
||||||
pixels.setPixelColor(h, pixels.getPixelColor(h) | 0x00ff0000);
|
pixels.setPixelColor(h, pixels.getPixelColor(h) | (bscale << 16));
|
||||||
pixels.setPixelColor(hr, pixels.getPixelColor(hr) | 0x00ff0000);
|
pixels.setPixelColor(hr, pixels.getPixelColor(hr) | (bscale << 16));
|
||||||
pixels.setPixelColor(m, pixels.getPixelColor(m) | 0x0000ff60);
|
pixels.setPixelColor(m, pixels.getPixelColor(m) | (bscale << 8) | (bscale >> 2));
|
||||||
pixels.setPixelColor(s, pixels.getPixelColor(s) | 0x000000ff);
|
pixels.setPixelColor(s, pixels.getPixelColor(s) | bscale);
|
||||||
pixels.show();
|
pixels.show();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue