Effect big_clock now show the seconds in a calmer way. Divisible-by-5 seconds are in another color.

This commit is contained in:
Fabian Schlenz 2019-10-02 06:17:20 +02:00
parent 083564caef
commit f42b5e1034
2 changed files with 41 additions and 7 deletions

View File

@ -5,10 +5,11 @@
class BigClockEffect : public Effect {
private:
CRGB _color_font = CRGB(0xAAAAAA);
CRGB _color_seconds = CRGB(0xFF0000);
CRGB _color_seconds_light = CRGB(0xFFFF00);
CRGB _color_seconds_dark = CRGB(0xFF0000);
void _draw_seconds();
void _draw_border_pixel(uint8_t second, CRGB* color);
void _draw_border_pixel(uint8_t second, uint8_t part, CRGB* color);
public:
void loop(uint16_t ms);

View File

@ -25,17 +25,28 @@ void BigClockEffect::loop(uint16_t ms) {
void BigClockEffect::_draw_seconds() {
uint8_t seconds = ntpClient.getSeconds();
for (int i=1; i<=seconds; i++) {
_draw_border_pixel(i, &_color_seconds);
_draw_border_pixel(i, 0, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
}
uint16_t millis = ntpClient.getEpochMillis() % 1000;
/*
// Enable this to have the next pixel move smoothly to its position
if (millis > 0) {
uint8_t part = 60 - ((60 - seconds) * millis / 1000);
_draw_border_pixel(part, &_color_seconds);
}
*/
uint8_t offset = 5 - ((millis % 1000) / 200);
uint8_t part = scale8(millis % 200, 200);
uint8_t number_to_show = (60 - seconds - offset) / 5 + 1;
for(uint8_t i = 0; i<number_to_show; i++) {
uint8_t pos = seconds + offset + i*5;
_draw_border_pixel(pos, part, (seconds + i + 1)%5==0 ? &_color_seconds_light : &_color_seconds_dark);
}
}
void BigClockEffect::_draw_border_pixel(uint8_t i, CRGB* color) {
uint8_t x, y;
void BigClockEffect::_draw_border_pixel(uint8_t i, uint8_t part, CRGB* color) {
/*uint8_t x, y;
if (i<=8) {
x = 7 + i;
y = 0;
@ -48,9 +59,31 @@ void BigClockEffect::_draw_border_pixel(uint8_t i, CRGB* color) {
} else if (i <= 53) {
x = 0;
y = 15 - i + 38;
} else {
} else if (i <= 60) {
x = i - 53;
y = 0;
} else {
return;
}
window->setPixel(x, y, color);
window->setPixel(x, y, color);*/
accum88 x, y;
if (i<=8) {
x = ((7+i)<<8) + part;
y = 0;
} else if (i<=23) {
x = 15<<8;
y = ((i-8)<<8) + part;
} else if (i<=38) {
x = ((38-i)<<8) - part;
y = 15<<8;
} else if (i<=53) {
x = 0;
y = ((53-i)<<8) - part;
} else if (i<=60) {
x = ((i-53)<<8) + part;
y = 0;
} else {
return;
}
window->setSubPixel(x, y, color);
}