Fixed big_clock effect and made it a lot nicer with moving pixels for seconds.
This commit is contained in:
parent
1122546853
commit
2ddd77eb5c
@ -5,17 +5,11 @@
|
|||||||
|
|
||||||
class BigClockEffect : public Effect {
|
class BigClockEffect : public Effect {
|
||||||
private:
|
private:
|
||||||
CRGB color_h = CRGB(0xFF0000);
|
CRGB _color_font = CRGB(0xAAAAAA);
|
||||||
CRGB color_m = CRGB(0x00FF00);
|
CRGB _color_seconds = CRGB(0xFF0000);
|
||||||
CRGB color_colon = CRGB(0xFFFF00);
|
|
||||||
|
|
||||||
void drawNumber(uint8_t number, int x, int y, CRGB color);
|
void _draw_seconds();
|
||||||
|
void _draw_border_pixel(uint8_t second, CRGB* color);
|
||||||
void drawText(char *text, int x, int y, CRGB color);
|
|
||||||
|
|
||||||
const unsigned char* font_char(const unsigned char* font, char c);
|
|
||||||
|
|
||||||
void drawSprite(const unsigned char* sprite, int xOffset, int yOffset, CRGB color);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void loop();
|
void loop();
|
||||||
|
@ -3,21 +3,54 @@
|
|||||||
#include "fonts.h"
|
#include "fonts.h"
|
||||||
#include "ntp.h"
|
#include "ntp.h"
|
||||||
|
|
||||||
void BigClockEffect::drawNumber(uint8_t number, int x, int y, CRGB color) {
|
void BigClockEffect::loop() {
|
||||||
char buffer[7];
|
window->clear();
|
||||||
sprintf(buffer, "%02d", number);
|
uint8_t h = ntpClient.getHours();
|
||||||
drawText(buffer, x, y, color);
|
window->drawChar(&font_numbers3x5_blocky, 6, 2, '0' + (h / 10), &_color_font);
|
||||||
|
window->drawChar(&font_numbers3x5_blocky, 11, 2, '0' + (h % 10), &_color_font);
|
||||||
|
|
||||||
|
uint8_t m = ntpClient.getMinutes();
|
||||||
|
window->drawChar(&font_numbers3x5_blocky, 6, 9, '0' + (m / 10), &_color_font);
|
||||||
|
window->drawChar(&font_numbers3x5_blocky, 11, 9, '0' + (m % 10), &_color_font);
|
||||||
|
|
||||||
|
uint8_t s = ntpClient.getSeconds();
|
||||||
|
if (s & 1) {
|
||||||
|
window->setPixel(3, 10, &_color_font);
|
||||||
|
window->setPixel(3, 12, &_color_font);
|
||||||
|
}
|
||||||
|
|
||||||
|
_draw_seconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BigClockEffect::drawText(char *text, int x, int y, CRGB color) {
|
void BigClockEffect::_draw_seconds() {
|
||||||
for (uint8_t i = 0; i < strlen(text); i++) {
|
uint8_t seconds = ntpClient.getSeconds();
|
||||||
window->drawChar(&font_numbers4x7, text[i], x + i * 4, y, &color);
|
for (int i=1; i<=seconds; i++) {
|
||||||
|
_draw_border_pixel(i, &_color_seconds);
|
||||||
|
}
|
||||||
|
uint16_t millis = ntpClient.getEpochMillis() % 1000;
|
||||||
|
if (millis > 0) {
|
||||||
|
uint8_t part = 60 - ((60 - seconds) * millis / 1000);
|
||||||
|
_draw_border_pixel(part, &_color_seconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BigClockEffect::loop() {
|
void BigClockEffect::_draw_border_pixel(uint8_t i, CRGB* color) {
|
||||||
window->clear();
|
uint8_t x, y;
|
||||||
drawNumber(ntpClient.getHours(), 0, 0, color_h);
|
if (i<=8) {
|
||||||
drawNumber(ntpClient.getMinutes(), 8, 0, color_m);
|
x = 7 + i;
|
||||||
drawNumber(ntpClient.getSeconds(), 8, 8, color_colon);
|
y = 0;
|
||||||
|
} else if (i<=23) {
|
||||||
|
x = 15;
|
||||||
|
y = i - 8;
|
||||||
|
} else if (i<= 38) {
|
||||||
|
x = 15 - i + 23;
|
||||||
|
y = 15;
|
||||||
|
} else if (i <= 53) {
|
||||||
|
x = 0;
|
||||||
|
y = 15 - i + 38;
|
||||||
|
} else {
|
||||||
|
x = i - 53;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
window->setPixel(x, y, color);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user