From 6667365739f63d158fddb061f9df8c60521a7020 Mon Sep 17 00:00:00 2001 From: Juergen Jung Date: Sun, 29 Jan 2017 14:18:23 +0100 Subject: [PATCH] Add length Property, fix bug with effect and setPixel --- src/schild.ino | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/schild.ino b/src/schild.ino index 96b93c2..7909317 100644 --- a/src/schild.ino +++ b/src/schild.ino @@ -5,7 +5,7 @@ #include #define PIN D1 -#define NUMPIXELS 30 +#define NUMPIXELS 144 uint16_t i=0,j=0,wait = 50; unsigned long lastCall = 0; @@ -41,10 +41,10 @@ bool onSetPixel(const HomieRange& range, const String& value){ stripNode.setProperty("pixel").send(value); return true; } - if (range.index < 0 || range.index > NUMPIXELS-1) { + if (range.index < 0 || range.index > pixels.numPixels()-1) { return false; } - effect == "none"; + effect = "none"; pixels.setPixelColor(range.index, value.toInt()); pixels.show(); stripNode.setProperty("pixel_" + String(range.index)).send(value); @@ -74,6 +74,17 @@ bool onSetClear(const HomieRange& range, const String& value){ stripNode.setProperty("clear").send(value); } +bool onSetLength(const HomieRange& range, const String& value){ + effect = "none"; + pixels.clear(); + pixels.show(); + int newLength = value.toInt(); + if(newLength > 0){ + pixels.updateLength(newLength); + } + stripNode.setProperty("length").send(value); +} + void loopHandler() { if (effect == "none"){ @@ -170,6 +181,7 @@ void setup() { stripNode.advertise("brightness").settable(onSetBrightness); stripNode.advertise("effect").settable(onSetEffect); stripNode.advertise("clear").settable(onSetClear); + stripNode.advertise("length").settable(onSetLength); pixels.begin(); pixels.clear();