Add possibility to set color1 and color2

This commit is contained in:
Juergen Jung 2017-02-19 14:49:00 +01:00
parent 7673b4e19c
commit 7a954bea55
1 changed files with 27 additions and 6 deletions

View File

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