set time to nightmode to 22o'clock

night brightness=0
loadanimaiton step into new function and some coments
This commit is contained in:
lukas 2021-05-12 21:20:32 +02:00
parent fd91a6071b
commit 3630918a6f
4 changed files with 56 additions and 38 deletions

View File

@ -30,8 +30,8 @@ void Clock::turnOn() {
} }
void Clock::paintAlwaysOnLeds() { void Clock::paintAlwaysOnLeds() {
printWord(types::es, Adafruit_NeoPixel::Color(150, 150, 0)); printWord(types::es, Adafruit_NeoPixel::Color(255, 255, 0));
printWord(types::ist, Adafruit_NeoPixel::Color(150, 0, 150)); printWord(types::ist, Adafruit_NeoPixel::Color(255, 0, 255));
} }
void Clock::printWord(const std::vector<uint8_t>& word, uint32_t color) { void Clock::printWord(const std::vector<uint8_t>& word, uint32_t color) {
@ -59,7 +59,7 @@ void Clock::refreshTime() {
const uint8_t minute = loctime->tm_min; const uint8_t minute = loctime->tm_min;
// enable night brighntess at 21' and disable it at 6' // enable night brighntess at 21' and disable it at 6'
if (hour >= 21 || hour <= 6) { if (hour >= 22 || hour <= 6) {
strip.setBrightness(NIGHTBRIGHTNESS); strip.setBrightness(NIGHTBRIGHTNESS);
} else { } else {
strip.setBrightness(DAYBRIGHTNESS); strip.setBrightness(DAYBRIGHTNESS);
@ -98,14 +98,14 @@ void Clock::setTime(uint8_t hour, uint8_t minute, bool twentyAfterSyntax, bool a
: hour == 0 || hour == 12 ? types::zwoelf : hour == 0 || hour == 12 ? types::zwoelf
: hourWord; : hourWord;
printWord(hourWord, Adafruit_NeoPixel::Color(0, 0, 150)); printWord(hourWord, Adafruit_NeoPixel::Color(0, 255, 255));
// print the minute words and the corresponding after/before half words // print the minute words and the corresponding after/before half words
printMinutes(minuteselector, twentyAfterSyntax); printMinutes(minuteselector, twentyAfterSyntax);
// uhr // uhr
if (minuteselector == 0 || alwaysClockWord) if (minuteselector == 0 || alwaysClockWord)
printWord(types::uhr, Adafruit_NeoPixel::Color(150, 0, 0)); printWord(types::uhr, Adafruit_NeoPixel::Color(255, 0, 0));
} }
void Clock::printMinutes(uint8_t minuteSelector, bool twentyAfterSyntax) { void Clock::printMinutes(uint8_t minuteSelector, bool twentyAfterSyntax) {
@ -126,7 +126,7 @@ void Clock::printMinutes(uint8_t minuteSelector, bool twentyAfterSyntax) {
else if (minuteSelector == 6) else if (minuteSelector == 6)
minuteWord = types::halb; minuteWord = types::halb;
printWord(minuteWord, Adafruit_NeoPixel::Color(0, 150, 0)); printWord(minuteWord, Adafruit_NeoPixel::Color(0, 255, 0));
// vor / nach // vor / nach
std::vector<uint8_t> vornachWord; std::vector<uint8_t> vornachWord;
@ -142,13 +142,13 @@ void Clock::printMinutes(uint8_t minuteSelector, bool twentyAfterSyntax) {
|| minuteSelector == 10 || minuteSelector == 11 || || minuteSelector == 10 || minuteSelector == 11 ||
((minuteSelector == 8) && twentyAfterSyntax)) // check if twentyafter enabled if yess -- display vor ((minuteSelector == 8) && twentyAfterSyntax)) // check if twentyafter enabled if yess -- display vor
vornachWord = types::vor; vornachWord = types::vor;
printWord(vornachWord, Adafruit_NeoPixel::Color(150, 150, 150)); printWord(vornachWord, Adafruit_NeoPixel::Color(255, 255, 255));
// halb // halb
if (minuteSelector >= 4 && minuteSelector <= 8) { if (minuteSelector >= 4 && minuteSelector <= 8) {
// only 3 times if twentyafter syntax is on // only 3 times if twentyafter syntax is on
if (!twentyAfterSyntax || (minuteSelector >= 5 && minuteSelector <= 7)) if (!twentyAfterSyntax || (minuteSelector >= 5 && minuteSelector <= 7))
printWord(types::halb, Adafruit_NeoPixel::Color(150, 0, 0)); printWord(types::halb, Adafruit_NeoPixel::Color(255, 0, 0));
} }
} }

View File

@ -16,8 +16,8 @@
// define the esp pin the stip is attached to // define the esp pin the stip is attached to
#define STRIPPIN D5 #define STRIPPIN D5
#define DAYBRIGHTNESS 255 #define DAYBRIGHTNESS 150
#define NIGHTBRIGHTNESS 40 #define NIGHTBRIGHTNESS 0
class Clock { class Clock {
private: private:

View File

@ -6,37 +6,41 @@
#include "Types.h" #include "Types.h"
void LoadAnimator::startLoadAnimation(Adafruit_NeoPixel* strip) { void LoadAnimator::startLoadAnimation(Adafruit_NeoPixel* strip) {
this->strip = strip;
if (!timer.active()) if (!timer.active())
timer.attach_ms(100, [this, strip]() { timer.attach_ms(100, std::bind(&LoadAnimator::animationStep, this));
if (y == 0 && x < 7) {
x++;
} else if (x == 7 && y < 4) {
y++;
} else if (y == 4 && x > 0) {
x--;
} else if (x == 0 && y > 0) {
y--;
}
uint8_t nr = types::convert(x + 2, y + 2);
strip->clear();
strip->setPixelColor(nr, Adafruit_NeoPixel::Color(0, 0, 150));
if (nro != 0)
strip->setPixelColor(nro, Adafruit_NeoPixel::Color(0, 0, 100));
if (nroo != 0)
strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 50));
if (nrooo != 0)
strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 25));
strip->show();
nrooo = nroo;
nroo = nro;
nro = nr;
});
} }
void LoadAnimator::stopLoadAnimation() { void LoadAnimator::stopLoadAnimation() {
timer.detach(); timer.detach();
} }
LoadAnimator::LoadAnimator() : timer(), x(0), y(0), nro(0), nroo(0), nrooo(0) {
LoadAnimator::LoadAnimator() : timer(), x(0), y(0), nro(0), nroo(0), nrooo(0){};
void LoadAnimator::animationStep() {
if (y == 0 && x < 7) {
x++;
} else if (x == 7 && y < 4) {
y++;
} else if (y == 4 && x > 0) {
x--;
} else if (x == 0 && y > 0) {
y--;
}
uint8_t nr = types::convert(x + 2, y + 2);
strip->clear();
strip->setPixelColor(nr, Adafruit_NeoPixel::Color(0, 0, 150));
if (nro != 0)
strip->setPixelColor(nro, Adafruit_NeoPixel::Color(0, 0, 100));
if (nroo != 0)
strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 50));
if (nrooo != 0)
strip->setPixelColor(nroo, Adafruit_NeoPixel::Color(0, 0, 25));
strip->show();
nrooo = nroo;
nroo = nro;
nro = nr;
} }

View File

@ -12,11 +12,25 @@ class LoadAnimator {
private: private:
Ticker timer; Ticker timer;
uint8_t x, y, nro, nroo, nrooo; uint8_t x, y, nro, nroo, nrooo;
Adafruit_NeoPixel *strip;
/**
* one animation step to process the animation
*/
void animationStep();
public: public:
LoadAnimator(); LoadAnimator();
/**
* start the animation if not already runnint
* @param strip pointer to strip object
*/
void startLoadAnimation(Adafruit_NeoPixel *strip); void startLoadAnimation(Adafruit_NeoPixel *strip);
/**
* stop the animation
*/
void stopLoadAnimation(); void stopLoadAnimation();
}; };