Update virtual pin value within a loop

I have one virtual pin. Depending on the virtual pin value I go into a loop. If i change the virtual pin value in the App, how do I get to exit the loop when the virtual pin changes?

Depending on your code… virtual pin state changes are usually read from the “App” via BLYNK_WRITE() functions, automatically upon said state change, no need to put the function itself in a loop

BLYNK_WRITE(Vx) // Vx is the number of Virtual Pin on a Button Widget
  int pinValue = param.asInt();  // the value of pinValue changes upon press (1) and release (0) of the Button Widget

However, you can (and usually do), assign the value of that virtual pin to a variable (i.e. pinValue), and that value of the variable can be viewed//compared/modified in any logic loop, just like in any other Arduino code.

So if I have a while pinValue = 1 loop and I change the pinValue from the App it will interupt the loop and leave the loop?

If by loop, you mean void loop(), and Blynk.run() is constantly being called, then yes.

Or even any other independent loop (i.e. closed) of your own that also contains a Blynk.run() <-- This is what keeps all the Blynk magic running in the background.


Just study all Doc’s and break down the various examples in the Sketch Builder as well as the code sprinkled around this forum… you will see many various ways to integrate Blynk into “normal” Arduino type code.