From 711d028e90e83cc502cd1a1a4f8341d2d0c6b174 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 30 May 2019 11:12:40 +0200 Subject: [PATCH] Added effect "confetti". Closes #16. --- include/effect_confetti.h | 12 ++++++++++++ include/functions.h | 2 ++ src/effect_confetti.cpp | 10 ++++++++++ src/effects.cpp | 4 ++++ src/functions.cpp | 6 ++++-- src/pitrix.cpp | 4 ++-- 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 include/effect_confetti.h create mode 100644 src/effect_confetti.cpp diff --git a/include/effect_confetti.h b/include/effect_confetti.h new file mode 100644 index 0000000..4009e73 --- /dev/null +++ b/include/effect_confetti.h @@ -0,0 +1,12 @@ +#ifndef effect_confetti_H +#define effect_confetti_H + +#include "Effect.h" +#include "my_fastled.h" + +class ConfettiEffect : public Effect { + void loop(); + boolean can_be_shown_with_clock(); +}; + +#endif diff --git a/include/functions.h b/include/functions.h index 8ab3637..e31befd 100644 --- a/include/functions.h +++ b/include/functions.h @@ -13,6 +13,8 @@ void setPixel(int i, CRGB color); void setPixel(Window win, int x, int y, CRGB color); +void addPixelColor(int i, CRGB color); + void clear(Window window, CRGB color); void clear(Window window); diff --git a/src/effect_confetti.cpp b/src/effect_confetti.cpp new file mode 100644 index 0000000..9830ea1 --- /dev/null +++ b/src/effect_confetti.cpp @@ -0,0 +1,10 @@ +#include "effect_confetti.h" +#include "config.h" +#include "functions.h" + +void ConfettiEffect::loop() { + fadeToBlackBy(leds, LED_COUNT, 1); + addPixelColor(random16(LED_COUNT), CHSV(random8(), 200, 255)); +} + +boolean ConfettiEffect::can_be_shown_with_clock() { return true; }; diff --git a/src/effects.cpp b/src/effects.cpp index 9e54581..617508b 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -13,6 +13,7 @@ #include "effect_matrix.h" #include "effect_twirl.h" #include "effect_cycle.h" +#include "effect_confetti.h" SimpleList* effects; SimpleList* cycle_effects; @@ -31,6 +32,7 @@ MultiDynamicEffect effect_multi_dynamic; MatrixEffect effect_matrix; CycleEffect effect_cycle; TwirlEffect effect_twirl; +ConfettiEffect effect_confetti; Effect* current_effect; @@ -51,11 +53,13 @@ void setup_effects() { effects->add((EffectEntry){"cycle", (Effect *)&effect_cycle}); effects->add((EffectEntry){"twirl", (Effect *)&effect_twirl}); effects->add((EffectEntry){"heart", (Effect*)&effect_anim_heart}); + effects->add((EffectEntry){"confetti", (Effect *)&effect_confetti}); cycle_effects->add(&effect_sinematrix3); cycle_effects->add(&effect_single_dynamic); cycle_effects->add(&effect_multi_dynamic); cycle_effects->add(&effect_matrix); + cycle_effects->add(&effect_confetti); current_effect = &effect_cycle; } diff --git a/src/functions.cpp b/src/functions.cpp index cdfd123..a0ecda7 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -19,8 +19,6 @@ int XYsafe(int x, int y) { return y*LED_WIDTH+x; } - - void setPixel(int x, int y, CRGB color) { if ( x >= LED_WIDTH) return; if ( y >= LED_HEIGHT) return; @@ -49,6 +47,10 @@ void setPixel(Window win, int x, int y, CRGB color) { setPixel(win.x + x, win.y + y, color); } +void addPixelColor(int i, CRGB color) { + leds[i] += color; +} + void clear(Window window, CRGB color) { for ( byte y = 0; y < window.h; y++) { for ( byte x = 0; x < window.w; x++) { diff --git a/src/pitrix.cpp b/src/pitrix.cpp index 6aaa2e5..f379aaf 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -22,14 +22,14 @@ long loop_started_at = 0; void setup() { Serial.begin(74880); - Serial.println("Core * Starting"); + LOGln("Core * Starting"); setup_effects(); wifi_setup(); ota_setup(); fastled_setup(); ntpClient.begin(); mqtt_setup(); - Serial.println("Core * Setup complete"); + LOGln("Core * Setup complete"); } void loop() {