Hello
So I’ve created a code that can auto-change colors of a led strip, fadng through all of them when, using a virtual pin. I have a few problems with it:
1.The fading doesn’t stop if I turn off the virtual button, reading on the web I’ve found out that the problem might be using delay insteam of simple timer. I’m very new to blynk and coding in general and I’d appreciate if someone would help me use the simpletimer function the same way as the delay is used in this code
2. I’d like to make the functon loop until I turn it off, it loops as many times as I turn it on, but keeping the virtual button on would only loop it once
Here’s the code:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxx";
const int red=D0;
const int green=D1;
const int blue=D2;
int redVal=0;
int greenVal=0;
int blueVal=0;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxx";
char pass[] = "xxxx";
>BlynkTimer timer;
>void stop(){
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
>void rgb(){
for(redVal=1023; redVal<1024; redVal++){
analogWrite(red, redVal);
delay(10);
}
for(greenVal=0; greenVal<1024; greenVal++){
analogWrite(green, greenVal);
delay(10);
}
for(redVal=1023; redVal>=0; redVal--){
analogWrite(red, redVal);
delay(10);
}
for(blueVal=0; blueVal<1024; blueVal++){
analogWrite(blue, blueVal);
delay(10);
}
for(greenVal=1023; greenVal>=0; greenVal--){
analogWrite(green, greenVal);
delay(10);
}
for(redVal=0; redVal<1024; redVal++){
analogWrite(red, redVal);
delay(10);
}
for(blueVal=1023; blueVal>=0; blueVal--){
analogWrite(blue, blueVal);
delay(10);
}
}
>BLYNK_WRITE(V5)
{
if(param.asInt() == 1) { // if Button sends 1
rgb(); // start the function
}
else stop();
}
>void setup()
{
// Debug console
Serial.begin(9600);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
>void loop()
{
Blynk.run();
timer.run();
}
I’m using nodemcu esp8266. Thank you