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.
Dear Pete,
I not sure is there any topic talking about calling multiple .setProperty and virtualWrite.
Blynk.setProperty
Blynk.virtualWrite
in my ESP32 code i have 10 tags to read by Blynk.
when i have only 1 tag, it works fine,
when i have more tags say 10 tags, seems like it will take more esp’s resources and slow down the response of esp for other purposes.
Any work around at Blynk commands?
Or i need to have different core to handle Blynk’s virtualWrite?
Hi Simon,
I don’t understand your question I’m afraid.
Maybe you should post your working “one tag” code and explain how you’d like to expand that, and what you’ve tried that didn’t work.
Pete.