Add length Property, fix bug with effect and setPixel

This commit is contained in:
Juergen Jung 2017-01-29 14:18:23 +01:00
parent 13abfe7afd
commit 6667365739
1 changed files with 15 additions and 3 deletions

View File

@ -5,7 +5,7 @@
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#define PIN D1 #define PIN D1
#define NUMPIXELS 30 #define NUMPIXELS 144
uint16_t i=0,j=0,wait = 50; uint16_t i=0,j=0,wait = 50;
unsigned long lastCall = 0; unsigned long lastCall = 0;
@ -41,10 +41,10 @@ bool onSetPixel(const HomieRange& range, const String& value){
stripNode.setProperty("pixel").send(value); stripNode.setProperty("pixel").send(value);
return true; return true;
} }
if (range.index < 0 || range.index > NUMPIXELS-1) { if (range.index < 0 || range.index > pixels.numPixels()-1) {
return false; return false;
} }
effect == "none"; effect = "none";
pixels.setPixelColor(range.index, value.toInt()); pixels.setPixelColor(range.index, value.toInt());
pixels.show(); pixels.show();
stripNode.setProperty("pixel_" + String(range.index)).send(value); 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); 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() { void loopHandler() {
if (effect == "none"){ if (effect == "none"){
@ -170,6 +181,7 @@ void setup() {
stripNode.advertise("brightness").settable(onSetBrightness); stripNode.advertise("brightness").settable(onSetBrightness);
stripNode.advertise("effect").settable(onSetEffect); stripNode.advertise("effect").settable(onSetEffect);
stripNode.advertise("clear").settable(onSetClear); stripNode.advertise("clear").settable(onSetClear);
stripNode.advertise("length").settable(onSetLength);
pixels.begin(); pixels.begin();
pixels.clear(); pixels.clear();