Write to virtual input pin

Hello fellow hackers. I’m working on (the design of) my first Blynk project, but before I start I want to know whether my wanted setup will work or not. I cannot find an answer to this question anywhere else on this forum.

The scenario is something like this: I have a switch button in the Android app connected to V1. I understand that BLYNK_WRITE(V1) will be called on my microcontroller if the button is clicked. The thing is that I want to be able to call Blynk.virtualWrite(V1, 1); on my microcontroller as well. When I do this, the button in the app should switch.

I suppose this will at least work passively (the value will change on the server, so when I close the app and reopen it, it would be changed, right?). I want at least this to be working, but in de ideal scenario the button will also switch actively without having to restart the app (with an allowed delay of a few seconds). Will this be the case?

Thank you for your help!

Hello. This scenario will work. The only thing is - button will automatically change state after pressed on app, even hardware didn’t receive it. You can use LED to be 100% command was delivered. Blynk.virtualWrite(V2, 255). Where V2 is LED on app

Thanks for your reply. I indeed thought about using a led in the app, but that would be kind of double since the button state should indicate the pin value.

I stille do nog have a clear answer though. When I change the pin value via the microcontroller, will the button state in the app change as wel when I have the app open? Or only if I restart the app? (I suppose the app syncs when I open it)

Yes. (If project is active). Any command is stored on server so you are able to get latest state both on hardware and on app.

This will work only for virtual pins