From 7a954bea55f04dfb8df150c24774723e102675f9 Mon Sep 17 00:00:00 2001 From: Juergen Jung Date: Sun, 19 Feb 2017 14:49:00 +0100 Subject: [PATCH] Add possibility to set color1 and color2 --- esp-wemos-schild/esp-wemos-schild.ino | 33 ++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/esp-wemos-schild/esp-wemos-schild.ino b/esp-wemos-schild/esp-wemos-schild.ino index a9f416c..5790312 100644 --- a/esp-wemos-schild/esp-wemos-schild.ino +++ b/esp-wemos-schild/esp-wemos-schild.ino @@ -23,6 +23,27 @@ HomieNode stripNode("strip", "strip"); HomieNode sensorNode("sensor", "sensor"); Bounce debouncer = Bounce(); +uint32_t color1 = pixels.Color(255, 0, 0); +uint32_t color2 = pixels.Color(0, 0, 255); + +bool onSetColor(const HomieRange& range, const String& value){ + if (!range.isRange || range.index < 0 || range.index > 1) { + return false; + } + switch(range.index) { + case 0: + color1 = value.toInt(); + break; + case 1: + color2 = value.toInt(); + break; + } + stripNode.setProperty("color_" + String(range.index)).send(value); +} + + + + bool onSetPixel(const HomieRange& range, const String& value){ if(!range.isRange) { pixels.None(); @@ -53,19 +74,19 @@ bool onSetEffect(const HomieRange& range, const String& value){ String effect = value; effect.toLowerCase(); if(effect == "scanner") { - pixels.Scanner(pixels.Color(255,0,0), 40); + pixels.Scanner(color1); } else if(effect == "randomscanner") { - pixels.Scanner(pixels.Color(255,0,0), 40,true); + pixels.Scanner(color1, 40, true); } else if(effect == "rainbowcycle") { pixels.RainbowCycle(50); } else if(effect == "theaterchase") { - pixels.TheaterChase(pixels.Color(0,0,255), pixels.Color(255,0,00), 100); + pixels.TheaterChase(color1, color2, 100); } else if(effect == "fade") { - pixels.Fade(pixels.Color(100,0,0),pixels.Color(0,0,100),200,100); + pixels.Fade(color1, color2, 200, 100); } else if(effect == "randomfade") { pixels.RandomFade(); @@ -97,7 +118,7 @@ bool onSetLength(const HomieRange& range, const String& value){ void loopHandler() { pixels.Update(); - int sensorValue = debouncer.read(); + bool sensorValue = debouncer.read(); if (Homie.isConfigured() && Homie.isConnected() && sensorValue != lastSensorValue) { sensorNode.setProperty("motion").send(sensorValue ? "true" : "false"); lastSensorValue = sensorValue; @@ -114,8 +135,8 @@ void setup() { Homie_setFirmware("schild", "1.0.0"); Homie.setLoopFunction(loopHandler); - stripNode.advertiseRange("pixel", 0, NUMPIXELS-1).settable(onSetPixel); + stripNode.advertiseRange("color", 0, 1).settable(onSetColor); stripNode.advertise("brightness").settable(onSetBrightness); stripNode.advertise("effect").settable(onSetEffect); stripNode.advertise("clear").settable(onSetClear);