Reading a Virtual Pin in a Function or Loop

Ideally I would like a virtual pin to start a loop and have the loop end when the value of the pin is changed. For this to happen, the loop needs to get the value of the pin to see it needs to stop looping. The problem is that BLYNK_WRITE can’t be called in a loop or a function. If it can be called, I’m not sure how to do it. I always run into an error saying I can’t define a function.

Here’s a simple example with a button, but it doesn’t work:

BLYNK_WRITE(V0){
    pinData=param.asInt; //This should either be 1 or 0.

    functionWithALoop(); //Calls on some function when the pin updated.
}

void functionWithALoop(){

    while(pinData=1){
        Code goes here; //Performs some task while the pin has a value of 1.
        BLYNK_WRITE(V0){ //Checks to see if the pin value has changed.
            pinData=param.asInt; 
        } 
    }

I learned C++ two days ago, so there might be a basic solution to this, but I just can’t find it anywhere. I’m just looking for a way to update a pin’s value inside a function that can be called in BLYNK_WRITE.

Try modding this to your needs…

BLYNK_WRITE(V2) // Run this "Strobe LED" function while V2 button pressed.
{
  int buttonValue = param.asInt();  // Get status of V2.
  if (buttonValue == 1) {  // If status of V1 is 1 then do stuff in if().
    digitalWrite(9, HIGH); // Turn on LED.
    delay(30); // Wait 20 millis but remember you are holding up the show.
    digitalWrite(9, LOW);  // Turn off LED.
    Blynk.run(); // Run rest of show in-between waiting for this loop to repeat or quit.
    int buttonValue = 0;  // Set V2 status to 0 to quit, unless button is still pushed (as per below)
    Blynk.syncVirtual(V2); // ...Then force BLYNK_WRITE(V2) function check of button status to determine if repeating or done.
  }
}