From af582f817c531dc352e0563d090bea78b6ba45e4 Mon Sep 17 00:00:00 2001 From: Jiri Praus Date: Wed, 23 Dec 2020 21:57:40 +0100 Subject: [PATCH] candle animation --- src/floower-esp32/floower.cpp | 24 ++++++++++++++++++------ src/floower-esp32/floower.h | 4 ++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/floower-esp32/floower.cpp b/src/floower-esp32/floower.cpp index 8d87282..12ce4a5 100644 --- a/src/floower-esp32/floower.cpp +++ b/src/floower-esp32/floower.cpp @@ -31,6 +31,8 @@ unsigned long Floower::touchStartedTime = 0; unsigned long Floower::touchEndedTime = 0; unsigned long Floower::lastTouchTime = 0; +const RgbColor candleColor(178, 45, 0); // 36 + Floower::Floower(Config *config) : config(config), animations(2), pixels(7, NEOPIXEL_PIN) {} void Floower::init() { @@ -294,7 +296,11 @@ void Floower::startAnimation(FloowerColorAnimation animation) { animations.StartAnimation(1, 10000, [=](const AnimationParam& param){ pixelsRainbowAnimationUpdate(param); }); } else if (animation == CANDLE) { - pixelsTargetColor = pixelsColor = RgbColor(255, 100, 0); // orange + pixelsTargetColor = pixelsColor = RgbColor(candleColor); // candle orange + for (uint8_t i = 0; i < 6; i++) { + candleOriginColors[i] = pixelsTargetColor; + candleTargetColors[i] = pixelsTargetColor; + } animations.StartAnimation(1, 100, [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); }); } } @@ -323,13 +329,19 @@ void Floower::pixelsRainbowAnimationUpdate(const AnimationParam& param) { } void Floower::pixelsCandleAnimationUpdate(const AnimationParam& param) { + pixels.SetPixelColor(0, pixelsTargetColor); + for (uint8_t i = 0; i < 6; i++) { + pixels.SetPixelColor(i + 1, RgbColor::LinearBlend(candleOriginColors[i], candleTargetColors[i], param.progress)); + } + if (param.state == AnimationState_Completed) { - HsbColor hsbColor = HsbColor(pixelsTargetColor); - for (uint8_t i = 0; i < 7; i++) { - hsbColor.B = random(40, 100) / 100.0; - pixels.SetPixelColor(i, hsbColor); + HsbColor candleHsbColor = HsbColor(candleColor); + for (uint8_t i = 0; i < 6; i++) { + candleHsbColor.B = random(20, 100) / 100.0; + candleOriginColors[i] = candleTargetColors[i]; + candleTargetColors[i] = RgbColor(candleHsbColor); } - animations.StartAnimation(param.index, random(20, 200), [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); }); + animations.StartAnimation(param.index, random(10, 400), [=](const AnimationParam& param){ pixelsCandleAnimationUpdate(param); }); } } diff --git a/src/floower-esp32/floower.h b/src/floower-esp32/floower.h index 05c79d5..cd4b500 100644 --- a/src/floower-esp32/floower.h +++ b/src/floower-esp32/floower.h @@ -122,6 +122,10 @@ class Floower { // acty unsigned long actyOffTime; + + // animations + RgbColor candleOriginColors[6]; + RgbColor candleTargetColors[6]; }; #endif