From 453e80aae5321113864f5af0f2d48bee3d0dc0d0 Mon Sep 17 00:00:00 2001 From: Dmitry Blinov Date: Thu, 7 Dec 2023 22:59:19 +0200 Subject: [PATCH] garland: update palettes, add random run animation --- code/espurna/garland.cpp | 31 ++++++++----- .../espurna/garland/animations/anim_randrun.h | 44 +++++++++++++++++++ code/espurna/garland/scene.h | 1 + 3 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 code/espurna/garland/animations/anim_randrun.h diff --git a/code/espurna/garland.cpp b/code/espurna/garland.cpp index bb475699..192fdffa 100644 --- a/code/espurna/garland.cpp +++ b/code/espurna/garland.cpp @@ -103,17 +103,13 @@ std::queue _command_queue; std::vector _command_sequence; // Palette should -std::array pals { +std::array pals { // palettes below are taken from http://www.color-hex.com/color-palettes/ (and modified) // RGB: Red,Green,Blue sequence Palette("RGB", {0xFF0000, 0x00FF00, 0x0000FF}), // Rainbow: Rainbow colors - Palette("Rainbow", {0xFF0000, 0xAB5500, 0xABAB00, 0x00FF00, 0x00AB55, 0x0000FF, 0x5500AB, 0xAB0055}), - - // RainbowStripe: Rainbow colors with alternating stripes of black - Palette("Stripe", {0xFF0000, 0x000000, 0xAB5500, 0x000000, 0xABAB00, 0x000000, 0x00FF00, 0x000000, - 0x00AB55, 0x000000, 0x0000FF, 0x000000, 0x5500AB, 0x000000, 0xAB0055, 0x000000}), + Palette("Rainbow", {0xFF0000, 0xFF8000, 0xFFFF00, 0x00FF00, 0x00FFFF, 0x0000FF, 0x5500AB}), // Party: Blue purple ping red orange yellow (and back). Basically, everything but the greens. // This palette is good for lighting at a club or party. @@ -126,7 +122,7 @@ std::array pals { Palette("Heat", {0x700070, 0xFF0000, 0xFFFF00, 0xFFFFCC}), // Fire: - Palette("Fire", {0x000000, 0x220000, 0x880000, 0xFF0000, 0xFF6600, 0xFFCC00}), + Palette("Fire", {0x300000, 0x440000, 0x880000, 0xFF0000, 0xFF6600, 0xFFCC00}), // Blue: Palette("Blue", {0xffffff, 0x0000ff, 0x00ffff}), @@ -137,8 +133,18 @@ std::array pals { // Lime: yellow green mix Palette("Lime", {0x51f000, 0x6fff00, 0x96ff00, 0xc9ff00, 0xf0ff00}), + Palette("Greens", {0xe5f2e5, 0x91f086, 0x48bf53, 0x11823b, 0x008000, 0x004d25, 0x18392b, 0x02231c}), + // Pastel: Pastel Fruity Mixture - Palette("Pastel", {0x75aa68, 0x5960ae, 0xe4be6c, 0xca5959, 0x8366ac}) + Palette("Pastel", {0x75aa68, 0x5960ae, 0xe4be6c, 0xca5959, 0x8366ac}), + + Palette("Summer", {0xb81616, 0xf13057, 0xf68118, 0xf2ab1e, 0xf9ca00, 0xaef133, 0x19ee9f, 0x0ea7b5, 0x0c457d}), + + Palette("Autumn", {0x8b1509, 0xce7612, 0x11805d, 0x801138, 0x32154b, 0x724c04}), + + Palette("Winter", {0xca9eb8, 0xfeeacf, 0xe0ecf2, 0x89e1c9, 0x72c3c5, 0x92c1ff, 0x3e6589, 0x052542}), + + Palette("Gaang", {0xe7a532, 0x46a8ca, 0xaf7440, 0xb4d29d, 0x9f5b72, 0x585c82}) }; constexpr uint16_t GarlandLeds { GARLAND_LEDS }; @@ -148,7 +154,7 @@ constexpr neoPixelType GarlandPixelType { NEO_GRB + NEO_KHZ800 }; Adafruit_NeoPixel pixels(GarlandLeds, GarlandPin, GarlandPixelType); Scene scene(&pixels); -std::array anims { +std::array anims { new AnimGlow(), new AnimStart(), new AnimPixieDust(), @@ -163,7 +169,8 @@ std::array anims { new AnimDolphins(), new AnimSalut(), new AnimFountain(), - new AnimWaves() + new AnimWaves(), + new AnimRandRun(), }; #define START_ANIMATION 1 @@ -673,7 +680,7 @@ byte Anim::rngb() { //------------------------------------------------------------------------------ void garlandEnabled(bool enabled) { - setSetting(NAME_GARLAND_ENABLED, _garland_enabled); + setSetting(NAME_GARLAND_ENABLED, enabled); if (_garland_enabled != enabled) { espurnaRegisterOnceUnique([]() { pixels.clear(); @@ -719,7 +726,7 @@ void garlandSetup() { scene.setPalette(_currentPalette); scene.setup(); - _currentDuration = secureRandom(EFFECT_UPDATE_INTERVAL_MIN, EFFECT_UPDATE_INTERVAL_MAX); + _currentDuration = 12000; // Start animation duration } #endif // GARLAND_SUPPORT diff --git a/code/espurna/garland/animations/anim_randrun.h b/code/espurna/garland/animations/anim_randrun.h new file mode 100644 index 00000000..af7d67de --- /dev/null +++ b/code/espurna/garland/animations/anim_randrun.h @@ -0,0 +1,44 @@ +#if GARLAND_SUPPORT + +#include "../anim.h" +#include "../palette.h" + +//------------------------------------------------------------------------------ +class AnimRandRun : public Anim { + private: + float speed; + float pos; + int dir; + + public: + AnimRandRun() : Anim("RandRun") { + } + + void SetupImpl() override { + pos = 0; + speed = ((float)secureRandom(20, 90)) / 100; + DEBUG_MSG_P(PSTR("[GARLAND] speed = %d\n"), (unsigned int)(speed*100)); + dir = secureRandom(10) > 5 ? -1 : 1; + + for (int i = 0; i < numLeds; ++i) + ledstmp[i] = palette->getRndInterpColor(); + + glowSetUp(); + } + + void Run() override { + pos += speed * dir; + if (pos >= numLeds) pos -= numLeds; + if (pos < 0) pos += numLeds; + + for (int i = 0; i < numLeds; ++i) { + int j = i + pos; + if (j >= numLeds) j -= numLeds; + leds[i] = ledstmp[j]; + glowForEachLed(i); + } + glowRun(); + } +}; + +#endif // GARLAND_SUPPORT diff --git a/code/espurna/garland/scene.h b/code/espurna/garland/scene.h index 4c548f7d..dae3f447 100644 --- a/code/espurna/garland/scene.h +++ b/code/espurna/garland/scene.h @@ -15,6 +15,7 @@ Inspired by https://github.com/Vasil-Pahomov/ArWs2812 (currently https://github. #include "animations/anim_fly.h" #include "animations/anim_glow.h" #include "animations/anim_pixiedust.h" +#include "animations/anim_randrun.h" #include "animations/anim_randcyc.h" #include "animations/anim_run.h" #include "animations/anim_salut.h"