diff --git a/include/effect_pixelclock.h b/include/effect_pixelclock.h new file mode 100644 index 0000000..a51cd07 --- /dev/null +++ b/include/effect_pixelclock.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Effect.h" +#include "my_fastled.h" + +class PixelClockEffect : public Effect { +private: + CRGB* _color_seconds; + CRGB* _color_minutes; +public: + PixelClockEffect(); + void start(); + void stop(); + void loop(); + bool can_be_shown_with_clock(); +}; diff --git a/src/effect_pixelclock.cpp b/src/effect_pixelclock.cpp new file mode 100644 index 0000000..f5c3115 --- /dev/null +++ b/src/effect_pixelclock.cpp @@ -0,0 +1,37 @@ +#include "effect_pixelclock.h" +#include "ntp.h" + +PixelClockEffect::PixelClockEffect() { + window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-7); +} + +void PixelClockEffect::start() { + _color_seconds = new CRGB(0x00FF00); + _color_minutes = new CRGB(0xFFFF00); +} + +void PixelClockEffect::stop() { + delete _color_seconds; + delete _color_minutes; +} + +void PixelClockEffect::loop() { + uint8_t x, y; // Temporary variables for calculating positions + window->clear(); + // Seconds + uint8_t seconds = ntpClient.getSeconds(); + for (uint8_t s=0; s<60; s++) { + x = window->width - 1 - s/10; + y = window->height - 1 - (s % 10); + if (s<=seconds) window->setPixel(x, y, _color_seconds); + } + + uint8_t minutes = ntpClient.getMinutes(); + for (uint8_t m=0; m<60; m++) { + x = 6 - m/10; + y = window->height - 1 - (m % 10); + if (m<=minutes) window->setPixel(x, y, _color_seconds); + } +} + +bool PixelClockEffect::can_be_shown_with_clock() { return true; } diff --git a/src/effects.cpp b/src/effects.cpp index 13baa98..ed6a48e 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -17,6 +17,7 @@ #include "effect_fire.h" #include "effect_firework.h" #include "effect_gol.h" +#include "effect_pixelclock.h" SimpleList* effects; SimpleList* cycle_effects; @@ -41,6 +42,7 @@ SnakeEffect effect_snake; FireEffect effect_fire; FireworkEffect effect_firework; GolEffect effect_gol; +PixelClockEffect effect_pixelclock; Effect* current_effect; @@ -67,6 +69,7 @@ void setup_effects() { effects->add((EffectEntry){"firework", (Effect *)&effect_firework}); effects->add((EffectEntry){"gol", (Effect *)&effect_gol}); effects->add((EffectEntry){"cake", (Effect *)&effect_anim_cake}); + effects->add((EffectEntry){"pixel_clock", (Effect *)&effect_pixelclock}); cycle_effects->add(&effect_sinematrix3); cycle_effects->add(&effect_multi_dynamic);