From f95589763e02c39d425cf21246ed70fb406a3b10 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 4 Jun 2019 05:58:23 +0200 Subject: [PATCH] Added FireEffect. Its values still need a bit of tweaking to look right... --- include/config.sample.h | 3 +++ include/effect_fire.h | 19 +++++++++++++++ src/effect_fire.cpp | 54 +++++++++++++++++++++++++++++++++++++++++ src/effects.cpp | 3 +++ 4 files changed, 79 insertions(+) create mode 100644 include/effect_fire.h create mode 100644 src/effect_fire.cpp diff --git a/include/config.sample.h b/include/config.sample.h index 567fe0d..1fb5b04 100644 --- a/include/config.sample.h +++ b/include/config.sample.h @@ -57,6 +57,9 @@ #define EFFECT_SNAKE_DIRECTION_CHANGE 10 #define EFFECT_SNAKE_SLOWDOWN 2 +#define EFFECT_FIRE_COOLDOWN 192 +#define EFFECT_FIRE_SPARK_CHANCE 5 + #ifdef DEBUG #define LOG(x) mqtt_log(x); Serial.print(x); #define LOGln(x) mqtt_log_ln(x); Serial.println(x); diff --git a/include/effect_fire.h b/include/effect_fire.h new file mode 100644 index 0000000..2d04fd2 --- /dev/null +++ b/include/effect_fire.h @@ -0,0 +1,19 @@ +#pragma once +#include "Effect.h" +#include "my_fastled.h" + +class FireEffect : public Effect { + private: + uint8_t* data; + uint8_t spark_temp(); + void cooldown(); + void spark(); + void propagate(); + void draw(); + static CRGBPalette16 palette; + + public: + void start(); + void stop(); + void loop(); +}; diff --git a/src/effect_fire.cpp b/src/effect_fire.cpp new file mode 100644 index 0000000..d58f382 --- /dev/null +++ b/src/effect_fire.cpp @@ -0,0 +1,54 @@ +#include "effect_fire.h" +#include "my_color_palettes.h" +#include "config.h" +#include "my_fastled.h" +#include "functions.h" + +void FireEffect::start() { + this->data = new uint8_t[LED_COUNT]; + for (int i=0; idata[i]=0; + for (int i=0; idata[i]=this->spark_temp(); +} + +void FireEffect::stop() { + delete [] this->data; +} + +void FireEffect::loop() { + cooldown(); + spark(); + propagate(); + draw(); +} + +void FireEffect::cooldown() { + for(int i=0; idata[i] = scale8(this->data[i], EFFECT_FIRE_COOLDOWN); // 240 or something +} + +void FireEffect::spark() { + for(int x=0; xdata[x] = this->spark_temp(); +} + +inline uint8_t FireEffect::spark_temp() { + return random8(180, 255); +} + +void FireEffect::propagate() { + for (int y=1; ydata[index] = scale8(this->data[below_index], 170) + scale8(this->data[below_index+1], 85); + } else if (x==LED_WIDTH-1) { + this->data[index] = scale8(this->data[below_index], 170) + scale8(this->data[below_index-1], 85); + } else { + this->data[index] = scale8(this->data[below_index], 128) + scale8(this->data[below_index-1], 64) + scale8(this->data[below_index+1], 64); + } + } +} + +void FireEffect::draw() { + for (int y=1; ydata[y*LED_WIDTH + x])); + } +} diff --git a/src/effects.cpp b/src/effects.cpp index c978182..d4b939c 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -15,6 +15,7 @@ #include "effect_cycle.h" #include "effect_confetti.h" #include "effect_snake.h" +#include "effect_fire.h" SimpleList* effects; SimpleList* cycle_effects; @@ -35,6 +36,7 @@ CycleEffect effect_cycle; TwirlEffect effect_twirl; ConfettiEffect effect_confetti; SnakeEffect effect_snake; +FireEffect effect_fire; Effect* current_effect; @@ -57,6 +59,7 @@ void setup_effects() { effects->add((EffectEntry){"heart", (Effect*)&effect_anim_heart}); effects->add((EffectEntry){"confetti", (Effect *)&effect_confetti}); effects->add((EffectEntry){"snake", (Effect *)&effect_snake}); + effects->add((EffectEntry){"fire", (Effect *)&effect_fire}); cycle_effects->add(&effect_sinematrix3); cycle_effects->add(&effect_single_dynamic);