From 79e6189857f4045bc94e6ffadfdea922c51bbf3d Mon Sep 17 00:00:00 2001 From: starcalc Date: Wed, 5 Jul 2017 01:01:41 +0200 Subject: [PATCH] Alle Pixel koennen ueber einen Befehl mit einer Farbe gezielt versehen --- pixelprojektor/NeoPatterns.cpp | 6 ++++- pixelprojektor/NeoPatterns.h | 2 +- pixelprojektor/pixelprojektor.ino | 38 +++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/pixelprojektor/NeoPatterns.cpp b/pixelprojektor/NeoPatterns.cpp index cc34c06..b19f3ca 100644 --- a/pixelprojektor/NeoPatterns.cpp +++ b/pixelprojektor/NeoPatterns.cpp @@ -104,6 +104,11 @@ void NeoPatterns::Reverse() { } } +void NeoPatterns::Stop(uint8_t interval) { + Interval = interval; + ActivePattern = NONE; +} + void NeoPatterns::None(uint8_t interval) { Interval = interval; if (ActivePattern != NONE) { @@ -183,7 +188,6 @@ void NeoPatterns::Scanner(uint32_t color1, uint8_t interval, bool colorful, bool Interval = interval; TotalSteps = (numPixels() - 1) * 2; Color1 = color1; - Color2 = color1; Index = 0; wPos = 0; this->colorful = colorful; diff --git a/pixelprojektor/NeoPatterns.h b/pixelprojektor/NeoPatterns.h index b439166..c818cc5 100644 --- a/pixelprojektor/NeoPatterns.h +++ b/pixelprojektor/NeoPatterns.h @@ -12,9 +12,9 @@ class NeoPatterns : public Adafruit_NeoPixel NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)()); void Update(); - void Reverse(); void None(uint8_t interval = 40); + void Stop(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); diff --git a/pixelprojektor/pixelprojektor.ino b/pixelprojektor/pixelprojektor.ino index 7cf445c..e0c2272 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 D2 //data pin for ws2812 (pixelprojektor @ ctdo: PIN 2) // Für pixelpad: Pin2 #define NUMPIXELS 64 NeoPatterns strip = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800, &StripComplete); @@ -65,6 +65,34 @@ bool onSetBrightness(const HomieRange& range, const String& value) { homieNode.setProperty("brightness").send(value); } +bool onSetPixels(const HomieRange& range, const String& value) { + + String remaining = value; + int i = 0; + // Kein Effekt + strip.Stop(); + do { + String current = remaining.substring(0, 7); + Homie.getLogger() << i << ":" << current << endl; + uint32_t currentcolor = strip.parseColor(current); + + strip.setPixelColor(strip.numToPos(i), currentcolor); + i++; + + remaining = remaining.substring(7); + + } while (remaining.length() > 2 && (i < strip.numPixels())); + Homie.getLogger() << " filling rest with black" << endl; + while (i < strip.numPixels()) { + strip.setPixelColor(strip.numToPos(i), strip.Color(0, 0, 0)); + i++; + } + + strip.show(); + + return true; +} + bool onSetEffect(const HomieRange& range, const String& value) { stopAfterCompletion = false; String effect = value; @@ -116,11 +144,10 @@ bool onSetEffect(const HomieRange& range, const String& value) { strip.RandomFadeSingle(p1); } else { - effect = "none"; strip.None(); } } - homieNode.setProperty("effect").send(effect); + homieNode.setProperty("effect").send(value); } bool onSetIcon(const HomieRange& range, const String& value) { @@ -170,15 +197,18 @@ void setup() { homieNode.advertise("clear").settable(onSetClear); homieNode.advertise("length").settable(onSetLength); homieNode.advertise("icon").settable(onSetIcon); + homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels); Homie.setup(); strip.begin(); strip.clear(); // strip.setBrightness(64); - strip.setBrightness(255); // HEEELLLLLLL :) + // strip.setBrightness(255); // HEEELLLLLLL :) + strip.setBrightness(10); // DEBUG! strip.show(); stopAfterCompletion = false; // Default + // strip.Plasma(); // Default effect ArduinoOTA.setHostname("pixelprojektor"); ArduinoOTA.onStart([]() {