Hi Les,
I’m a bit confused as to why you’re doing this.
You don’t need to keep polling the virtual pins to see if the value has changed. This is the beauty of the BLYNK_WRITE and BLYNK_WRITE_DEFAULT functions - they are in effect callback functions that ‘fire’ automatically when the value of whatever is attached to them in the app changes.
In effect, they are interrupt driven functions that sit there dormant until a change occurs.
The Blynk.syncVirtual(Vx) function is really intended to synchronise the values of your variables that are changed within the BLYNK_WRITE functions with those on the Blynk server. This is really only needed at startup, and is there to avoid the users having to go into the app and ‘dirty’ the values of each widget by changing them and causing a subsequent BLYNK_WRITE within the code.
Blynk also has a special callback function that is triggered whenever the hardware connects to the server and this is called BLYNK_CONNECTED(), and their is where the Blynk.syncVirtual(Vx) commands would normally live.
There is also a Blynk.syncAll command that causes every pin (both digital and virtual) to be updated, but this is a bit of a sledgehammer to crack a nut and using this tool can cause timeout problems.
To answer your question, it is possible to loop through virtual pins in a loop, this is an example:
for(int loop=0;loop<=7;loop++)
{
Blynk.syncVirtual(loop); // This forces the BLYNK_WRITE_DEFAULT callback function to trigger for each virtual pin in turn
}
This is from my example code here:
and it lives in the BLYNK_CONNECTED() callback at the bottom of the code.
The code also uses the BLYNK_WRITE_DEFAULT() callback to make the code neater, otherwise 16 BLYNK_WRITE callbacks would be needed, or potentially 128 in the following post.
Pete.