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();