BLYNK_WRITE and BlynkTimer

Hi Blinkers,
A query…
Say you have a void XX () within a BLYNK_WRITE function am I right to assume i don’t need to create a timer.setInterval() action for the void XX() as it is updated by the Blynk.syncAll(); ?

I don’t really understand the question. Can you give a code example?

Pete.

Yes, I think, if I understand.

The Blynk timer is used to call a function a specified number of times or at a specified frequency.

Blynk write is called when a virtual pin is updated app side or when syncall or sync(x) is called.

A Blynk function like

BLYNK_WRITE(vPin) {
// do something
}

or a Arduino function like

MyFunction() {
// do something
}

Both can be called from various methods…

Blynk Function - Timer command, App Widget state change, Sync command, Bridge command

Arduino Function - Timer command, Function call command

As per this topic, a timer can call either one, but just with different commands…

Blynk Function - timer.setInterval(1000L, Blynk.syncVirtual(vPin)); // Match the vPin with that of the Blynk function

Arduino Function - timer.setInterval(1000L, MyFunction());

2 Likes

Ok. Thanks

@Gunner Thanks that is clear. So just to confirm if a BLYNK_WRITE function is used it only updates if a change happens on the App, but by adding a timer to a Blynk.syncVirtual you effectively update to what you want.

Being a Blynk function, it is only called with Blynk commands… typically Widget state/input changes initiated from the App.

The Sync command tells the Server to resend the last known value to the corresponding function, thus can act like a programmatically controlled function call.

If you want to change the value before calling the function then do so with a Blynk.virtualWrite(vPin, value) comand, followed by the Blynk.syncVirtual(vPin);

1 Like

Got it. Thanks for clarifying