enable nightmode brightness at night

add some comments
This commit is contained in:
lukas 2021-04-06 21:22:09 +02:00
parent 4ed74164e8
commit fd91a6071b
2 changed files with 14 additions and 0 deletions

View File

@ -10,6 +10,7 @@ Clock::Clock() : strip(NUMPIXELS, STRIPPIN, NEO_GRB + NEO_KHZ800), animator(), r
void Clock::init() {
strip.begin();
strip.setBrightness(DAYBRIGHTNESS);
// initialize clock ticker
turnOn();
@ -42,10 +43,13 @@ void Clock::printWord(const std::vector<uint8_t>& word, uint32_t color) {
void Clock::refreshTime() {
// grab the current instant in unix seconds
time_t now = time(nullptr);
// if not time is set (only seconds since start) start animation
if (now <= 604800) {
animator.startLoadAnimation(&strip);
return;
}
animator.stopLoadAnimation();
strip.clear();
@ -54,6 +58,13 @@ void Clock::refreshTime() {
const uint8_t hour = loctime->tm_hour;
const uint8_t minute = loctime->tm_min;
// enable night brighntess at 21' and disable it at 6'
if (hour >= 21 || hour <= 6) {
strip.setBrightness(NIGHTBRIGHTNESS);
} else {
strip.setBrightness(DAYBRIGHTNESS);
}
paintAlwaysOnLeds();
setTime(hour, minute, this->twentyAfterSyntax, this->clockAlwaysOn);

View File

@ -16,6 +16,9 @@
// define the esp pin the stip is attached to
#define STRIPPIN D5
#define DAYBRIGHTNESS 255
#define NIGHTBRIGHTNESS 40
class Clock {
private:
Adafruit_NeoPixel strip{};