Virtual Pins function loop/stop and RGB Strip fade effects

@dragos

could you try that ?

void rgb() {
  if (btnState == 1) {
    timer.setTimeout(1000L, []() { // you have to ajust 1000L according your need
      for (redVal = 1023; redVal < 1024; redVal++) {
        analogWrite(red, redVal);
      }

      timer.setTimeout(1000L, []() {
        for (greenVal = 0; greenVal < 1024; greenVal++) {
          analogWrite(green, greenVal);
        }
        timer.setTimeout(1000L, []() {
          for (redVal = 1023; redVal >= 0; redVal--) {
            analogWrite(red, redVal);
          }
          timer.setTimeout(1000L, []() {
            for (blueVal = 0; blueVal < 1024; blueVal++) {
              analogWrite(blue, blueVal);
            }
            timer.setTimeout(1000L, []() {
              for (greenVal = 1023; greenVal >= 0; greenVal--) {
                analogWrite(green, greenVal);
              }
              timer.setTimeout(1000L, []() {
                for (redVal = 0; redVal < 1024; redVal++) {
                  analogWrite(red, redVal);
                }
                timer.setTimeout(1000L, []() {
                  for (blueVal = 1023; blueVal >= 0; blueVal--) {
                    analogWrite(blue, blueVal);
                  }

                });  // END Timer Function
              });  // END Timer Function
            });  // END Timer Function
          });  // END Timer Function
        });  // END Timer Function
      });  // END Timer Function
    });  // END Timer Function
    
  } else {
    break; //if btnState =0
  }
}

BLYNK_WRITE(V5)
{
  int btnState = param.asInt(); // Button sends 1 or 0
  rgb();             // start the function
}
1 Like