Added V0.7 (Not Tested) rgb. Testes if every led is able to display Red, Green and Blue

This commit is contained in:
Nicolas Bachschwell 2017-04-26 08:47:13 +02:00
parent b98ca673ce
commit 57023c72bb

View File

@ -3,7 +3,7 @@
* Normally befor sending it to git, I am testing it. But I can't test it while in school... * Normally befor sending it to git, I am testing it. But I can't test it while in school...
* So the code here might work or not. But I should be able to garantee that it is working on a Node-MCU (ESP8266) when I tested it. * So the code here might work or not. But I should be able to garantee that it is working on a Node-MCU (ESP8266) when I tested it.
* *
* TESTED: YES * TESTED: No (rgb not tested yet)
*/ */
#include <Arduino.h> #include <Arduino.h>
#include <Homie.h> #include <Homie.h>
@ -31,6 +31,8 @@ double fadeRed = 0;
double fadeGreen = 0; double fadeGreen = 0;
double fadeBlue = 0; double fadeBlue = 0;
int brightness = 0;
int nextLed = 0; int nextLed = 0;
//MQTT RECIEVE[devices/stripbed/strip/leds/set] (EVENT: Fired when MQTT Message has been recieved) //MQTT RECIEVE[devices/stripbed/strip/leds/set] (EVENT: Fired when MQTT Message has been recieved)
@ -123,7 +125,6 @@ bool onLedsShouldChange(String value){
else if(actionToDo == "oneled"){ else if(actionToDo == "oneled"){
reset(); reset();
thingToDo = "oneLed"; thingToDo = "oneLed";
Serial.println("Ha: " + String(root["leds"].size()));
for(int count = 0;count < root["leds"].size(); count++){ for(int count = 0;count < root["leds"].size(); count++){
strip.setPixelColor((int)root["leds"][count]["id"], strip.Color((int)root["leds"][count]["red"], (int)root["leds"][count]["green"], (int)root["leds"][count]["blue"])); strip.setPixelColor((int)root["leds"][count]["id"], strip.Color((int)root["leds"][count]["red"], (int)root["leds"][count]["green"], (int)root["leds"][count]["blue"]));
} }
@ -131,6 +132,14 @@ bool onLedsShouldChange(String value){
Homie.setNodeProperty(stripNode, "last", "{\"state\":\"success\"}"); Homie.setNodeProperty(stripNode, "last", "{\"state\":\"success\"}");
return true; return true;
} }
else if(actionToDo == "rgb"){
reset();
thingToDo = "rgb";
toDelay = root["time"];
brightness = root["brightness"]
Homie.setNodeProperty(stripNode, "last", "{\"state\":\"success\"}");
return true;
}
else{ else{
Homie.setNodeProperty(stripNode, "last", "{\"state\":\"error\",id:\"unknownCommandError\",msg:\"No such Command.\"}"); //Jeder andere ACTION command wird hier als ungültig abgestempelt. Homie.setNodeProperty(stripNode, "last", "{\"state\":\"error\",id:\"unknownCommandError\",msg:\"No such Command.\"}"); //Jeder andere ACTION command wird hier als ungültig abgestempelt.
return true; return true;
@ -142,7 +151,7 @@ void setup(){
strip.begin(); strip.begin();
strip.show(); strip.show();
Homie.setFirmware("Ledstrip Control", "0.6"); //Firmware: Ledstrip Control: v0.6 (New feature: + 0.1 ; Bugfixe/Improvement of a feature: + 0.0.1) Homie.setFirmware("Ledstrip Control", "0.7"); //Firmware: Ledstrip Control: v0.6 (New feature: + 0.1 ; Bugfixe/Improvement of a feature: + 0.0.1)
stripNode.subscribe("leds", onLedsShouldChange); //MQTT Subscribe stripNode.subscribe("leds", onLedsShouldChange); //MQTT Subscribe
Homie.registerNode(stripNode); //HomieNode REGISTER Homie.registerNode(stripNode); //HomieNode REGISTER
Homie.setup(); //Homie SETUP Homie.setup(); //Homie SETUP
@ -277,6 +286,48 @@ void loop(){
strip.setPixelColor(0, strip.Color((int)fadeRed, (int)fadeGreen, (int)fadeBlue)); strip.setPixelColor(0, strip.Color((int)fadeRed, (int)fadeGreen, (int)fadeBlue));
strip.show(); strip.show();
} }
else if(thingToDo == "rgb"){ //rgb LedStriptest animation (Fullversion will be added later).
if(momentStep == 0){
if(nextLed < NUMPIXELS){
strip.setPixelColor(nextLed, strip.Color(brightness, 0, 0));
strip.show();
++nextLed;
}
else if(nextLed == NUMPIXELS){
nextLed = 1;
strip.setPixelColor(0, strip.Color(0, brightness, 0));
strip.show();
momentStep = 1;
}
}
else if(momentStep == 1){
if(nextLed < NUMPIXELS){
strip.setPixelColor(nextLed, strip.Color(0, brightness, 0));
strip.show();
++nextLed;
}
else if(nextLed == NUMPIXELS){
nextLed = 1;
strip.setPixelColor(0, strip.Color(0, 0, brightness));
strip.show();
momentStep = 2;
}
}
else if(momentStep == 2){
if(nextLed < NUMPIXELS){
strip.setPixelColor(nextLed, strip.Color(0, 0, brightness));
strip.show();
++nextLed;
}
else if(nextLed == NUMPIXELS){
nextLed = 1;
strip.setPixelColor(0, strip.Color(brightness, 0, 0));
strip.show();
momentStep = 0;
}
}
startNextAction = millis();
}
} }
void changeLedColor(){ void changeLedColor(){