From e897c6bdcd6879fd3ed8d5ba54ef9924c1fb62ff Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 19 Jun 2019 22:17:39 +0200 Subject: [PATCH] New Effect: DvdEffect --- include/effect_dvd.h | 17 +++++++++++++++++ src/effect_dvd.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 include/effect_dvd.h create mode 100644 src/effect_dvd.cpp diff --git a/include/effect_dvd.h b/include/effect_dvd.h new file mode 100644 index 0000000..1ec0c17 --- /dev/null +++ b/include/effect_dvd.h @@ -0,0 +1,17 @@ +#pragma once +#include "Effect.h" + +class DvdEffect : public Effect { +private: + Window* window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); + uint8_t _x = 0; + uint8_t _y = 0; + int8_t _x_dir = 1; + int8_t _y_dir = 1; + CRGB _color; +public: + DvdEffect(); + ~DvdEffect(); + void loop() override; + bool can_be_shown_with_clock() override; +}; diff --git a/src/effect_dvd.cpp b/src/effect_dvd.cpp new file mode 100644 index 0000000..ead0091 --- /dev/null +++ b/src/effect_dvd.cpp @@ -0,0 +1,37 @@ +#include "effect_dvd.h" +#include "my_fastled.h" + +void DvdEffect::loop() { + bool dir_changed = false; + EVERY_N_MILLISECONDS( 250 ) { + _x += _x_dir; + _y += _y_dir; + + if (_x == 0 || _x + EFFECT_DVD_WIDTH >= window->width) { + _x_dir = -_x_dir; + dir_changed = true; + } + if (_y == 0 || _y + EFFECT_DVD_HEIGHT >= window->height) { + _y_dir = -_y_dir; + dir_changed = true; + } + } + + window->clear(); + + for (int x=0; xsetPixel(_x + x, _y + y, (CRGB*)&_color); + } + + if (dir_changed) _color = (CRGB)CHSV(random8(), 255, 255); +} + +bool DvdEffect::can_be_shown_with_clock() { return true; } + +DvdEffect::DvdEffect() { + _color = CHSV(random8(), 255, 255); +} + +DvdEffect::~DvdEffect() { + delete window; +}