From 9fb6b1c089e080c447d89a16a6b3ec672107fd43 Mon Sep 17 00:00:00 2001 From: starcalc Date: Fri, 3 Mar 2017 18:27:51 +0100 Subject: [PATCH] =?UTF-8?q?Effekt=20RANDOM,=20Effekt=20FILL=20sauber=20hin?= =?UTF-8?q?zugef=C3=BCgt,=20werden=20auch=20korrekt=20abgeschaltet.=20Ener?= =?UTF-8?q?gieverbrauch=20gesenkt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pixelprojektor/NeoPatterns.cpp | 18 +++++++++++++++++- pixelprojektor/NeoPatterns.h | 8 ++++++-- pixelprojektor/pixelprojektor.ino | 5 +++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/pixelprojektor/NeoPatterns.cpp b/pixelprojektor/NeoPatterns.cpp index b510538..de2697b 100644 --- a/pixelprojektor/NeoPatterns.cpp +++ b/pixelprojektor/NeoPatterns.cpp @@ -49,11 +49,17 @@ void NeoPatterns::Update() { case PLASMA: PlasmaUpdate(); break; + case FILL: + break; + case RANDOM: + break; case NONE: break; default: break; } + } else { + delay(1); } } @@ -98,7 +104,8 @@ void NeoPatterns::Reverse() { } } -void NeoPatterns::None() { +void NeoPatterns::None(uint8_t interval) { + Interval = interval; if (ActivePattern != NONE) { clear(); show(); @@ -290,6 +297,7 @@ void NeoPatterns::RandomBuffer() void NeoPatterns::Random() { None(); // Stop all other effects + ActivePattern = RANDOM; for (int i = 0; i < numPixels(); i++) { setPixelColor(i, Wheel(random(0, 256))); } @@ -413,6 +421,9 @@ void NeoPatterns::Icon(uint8_t fontchar, String iconcolor, uint8_t interval) SavedIndex = Index; SavedColor1 = Color1; SavedDirection = Direction; + SavedPlasmaPhase = PlasmaPhase; + SavedPlasmaPhaseIncrement = PlasmaPhaseIncrement; + SavedPlasmaColorStretch = PlasmaColorStretch; ActivePattern = ICON; Interval = interval; TotalSteps = 80; @@ -450,6 +461,9 @@ void NeoPatterns::IconComplete() Index = SavedIndex; Color1 = SavedColor1; Direction = SavedDirection; + PlasmaPhase = SavedPlasmaPhase; + PlasmaPhaseIncrement = SavedPlasmaPhaseIncrement; + PlasmaColorStretch = SavedPlasmaColorStretch; } // Based upon https://github.com/johncarl81/neopixelplasma @@ -516,6 +530,7 @@ void NeoPatterns::PlasmaUpdate() show(); } + /****************** Helper functions ******************/ void NeoPatterns::SetColor1(uint32_t color) { @@ -546,6 +561,7 @@ void NeoPatterns::ColorSet(uint32_t color) void NeoPatterns::ColorSetParameters(String parameters) { None(); + ActivePattern = FILL; ColorSet(parseColor(parameters)); } diff --git a/pixelprojektor/NeoPatterns.h b/pixelprojektor/NeoPatterns.h index 24a196a..bd02db2 100644 --- a/pixelprojektor/NeoPatterns.h +++ b/pixelprojektor/NeoPatterns.h @@ -2,7 +2,7 @@ #include "font.h" // Pattern types supported: -enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA }; +enum pattern { NONE, RAINBOW_CYCLE, THEATER_CHASE, COLOR_WIPE, SCANNER, FADE, RANDOM_FADE, SMOOTH, ICON, RANDOM_FADE_SINGLE, PLASMA, FILL, RANDOM }; // Patern directions supported: enum direction { FORWARD, REVERSE }; @@ -14,7 +14,7 @@ class NeoPatterns : public Adafruit_NeoPixel void Update(); void Reverse(); - void None(); + void None(uint8_t interval = 40); void RainbowCycle(uint8_t interval, direction dir = FORWARD); void RainbowCycleUpdate(); void TheaterChase(uint32_t color1, uint32_t color2, uint8_t interval, direction dir = FORWARD); @@ -92,8 +92,12 @@ class NeoPatterns : public Adafruit_NeoPixel uint8_t FontChar; float PlasmaPhase; + float SavedPlasmaPhase; float PlasmaPhaseIncrement; + float SavedPlasmaPhaseIncrement; float PlasmaColorStretch; + float SavedPlasmaColorStretch; + uint32_t DimColor(uint32_t color); void Increment(); diff --git a/pixelprojektor/pixelprojektor.ino b/pixelprojektor/pixelprojektor.ino index b4dd61c..6945d90 100644 --- a/pixelprojektor/pixelprojektor.ino +++ b/pixelprojektor/pixelprojektor.ino @@ -6,7 +6,7 @@ #include #endif -#define PIN 2 //data pin for ws2812 (pixelprojektor @ ctdo: PIN 2) +#define PIN D1 //data pin for ws2812 (pixelprojektor @ ctdo: PIN 2) #define NUMPIXELS 64 NeoPatterns strip = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800, &StripComplete); @@ -98,7 +98,8 @@ bool onSetEffect(const HomieRange& range, const String& value) { } else if (effect == "plasma") { strip.Plasma(); - } else { + } + else { // Test whether command with parameters was sent int sep = value.indexOf("|"); String command = value.substring(0, sep);