2019-05-21 03:52:57 +00:00
|
|
|
class Clock : public Effect {
|
|
|
|
private:
|
|
|
|
CRGB color_h = CRGB(0xFF0000);
|
|
|
|
CRGB color_m = CRGB(0x00FF00);
|
|
|
|
CRGB color_colon = CRGB(0xFFFF00);
|
|
|
|
|
|
|
|
void drawNumber(uint8_t number, int x, int y, CRGB color) {
|
|
|
|
char buffer[7];
|
|
|
|
sprintf(buffer, "%02d", number);
|
|
|
|
drawText(buffer, x, y, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawText(char *text, int x, int y, CRGB color) {
|
|
|
|
for (int i = 0; i < strlen(text); i++) {
|
|
|
|
drawSprite(font_char(numbers4x7, text[i]), x + i * 4, y, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char* font_char(unsigned char* font, char c) {
|
|
|
|
return &font[(c - 48) * 4];
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawSprite(unsigned char* sprite, int xOffset, int yOffset, CRGB color) {
|
|
|
|
for ( byte y = 0; y < 7; y++) {
|
|
|
|
for ( byte x = 0; x < 4; x++) {
|
|
|
|
bool on = (sprite[x] >> y & 1) * 255;
|
|
|
|
if (on) {
|
|
|
|
leds[ XYsafe(x + xOffset, y + yOffset) ] = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
Clock() {}
|
|
|
|
void loop() {
|
|
|
|
clear();
|
|
|
|
drawNumber(ntpClient.getHours(), 0, 0, color_h);
|
|
|
|
drawNumber(ntpClient.getMinutes(), 8, 0, color_m);
|
|
|
|
/*if (ntpClient.getSeconds() & 1) {
|
|
|
|
leds[XYsafe(13, 2)] = color_colon;
|
|
|
|
leds[XYsafe(13, 5)] = color_colon;
|
|
|
|
}*/
|
|
|
|
drawNumber(ntpClient.getSeconds(), 8, 8, color_colon);
|
|
|
|
}
|
|
|
|
};
|
2019-05-21 18:28:11 +00:00
|
|
|
|
|
|
|
class SmallClock : public Effect {
|
|
|
|
private:
|
|
|
|
CRGB color_h = CRGB(0xFF0000);
|
|
|
|
CRGB color_m = CRGB(0x00FF00);
|
|
|
|
CRGB color_colon = CRGB(0xFFFF00);
|
|
|
|
|
|
|
|
public:
|
|
|
|
SmallClock() {}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
clear();
|
|
|
|
int h = ntpClient.getHours();
|
|
|
|
drawDigit(numbers3x5, 3, 5, 0, 11, h/10, color_h);
|
|
|
|
drawDigit(numbers3x5, 3, 5, 4, 11, h%10, color_h);
|
|
|
|
int m = ntpClient.getMinutes();
|
|
|
|
drawDigit(numbers3x5, 3, 5, 9, 11, m/10, color_m);
|
|
|
|
drawDigit(numbers3x5, 3, 5, 13, 11, m%10, color_m);
|
|
|
|
if (ntpClient.getSeconds() & 1) {
|
|
|
|
leds[XYsafe(7, 12)] = color_colon;
|
|
|
|
leds[XYsafe(7, 14)] = color_colon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|