BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Programatically call V numbers

I can’t believe this question hasn’t been asked loads of times before. I’ve searched and found nothing.
Ss it possible to substitute the V number with a variable so that one can call one of many widgets by setting the variable?

Yes. The leading “V” is optional, so you can do…

Blynk.virtualWrite(V1,value);

Blynk.virtualWrite(1,value);

int myPin = 1;
Blynk.virtualWrite(myPin,value);

and they all produce the same result.

Just be careful, if you put this into a loop, that you don’t exceed more than 1 virtualWrite every 0.1 seconds otherwise you maty run into server flooding issues.

The other potentially useful tool is BLYNK_WRITE_DEFAULT(), which saves having to have multiple BLYNK_WRITE(vPin) callbacks in the same sketch.

BLYNK_WRITE_DEFAULT()
{
  int widget_pin = request.pin;      // Which virtual pin triggered this BLYNK_WRITE_DEFAULT callback?
  int widget_value = param.asInt();  // Get the value from the virtual pin (0 = off, 1 = on)
}

Juist be aware that this only works with virtual pin numbers of 0-127.

Pete.