It’s allowed to do something like this?
int new_value[4] = {2, 4, -8, 3};
for (int pin = 0; pin < 4; pin++)
{
Blynk.virtualWrite( pin + 4 , new_value[pin]);
}
It’s allowed to do something like this?
int new_value[4] = {2, 4, -8, 3};
for (int pin = 0; pin < 4; pin++)
{
Blynk.virtualWrite( pin + 4 , new_value[pin]);
}
Looks ok as it only iterates 4 times. If it gives you any problems slip a delay(x) in the for loop where x is say somewhere from 1 to 10.
it is perfectly ok, i also use this method quite often.
the drawback is, that you have to allocate virtual pins with a good strategy, because if you have to make changes later (eg need more elements in the array), and the next virtual pins are already reserved, you have to edit both on hw and app side.
usually, i leave 10 virtual pins unallocated after each array, to have space if future expansion is needed.
I have used this method for a slower syncAll option; 5ms in between each Blynk.syncVirtual()
. It would work the exact same way for Blynk.virtualWrite()
BLYNK_WRITE_DEFAULT() { // Button in momentary mode
if (request.pin == 127 and param.asInt() == 1) { // Checks if the triggered widget is set for V127 and it's state is HIGH
timer.setTimer(5, BlynkSyncAllHack, 126); // 5ms pause then run function, repeat 126 times.
}
}
void BlynkSyncAllHack() {
Blynk.syncVirtual(Vcount); // Generate a vPin sync for each count
Vcount++;
if (Vcount == 126) {
Vcount = 0;
}
}
interesting approach. but why would you need a slow syncall?
It (the standard one) was causing disconnects on my Mega testbench… probably because I have so many vpins in operation.