Trigger to execute a function then show value

Hello all,
First time using Blynk, I’m using it with a NodeMcu v1.0 board, I want when I press a push button from the App some instructions get executed on the board then the value get displayed on the App.
Something like this (not real code :sweat_smile:)

if (button pressed) {
int x=random_number; //generating random number
virtualWrite(V0,x); //show it on the App
} //if I don't press the button don't change "x" value

I’ve worked on this project but I had some problems in communication, so I’m now trying Blynk but I’m still having difficulties :cry:
Thanks

Setup a button on a virtual pin, say V1, and a value widget on V2.

BLYNK_WRITE(V1) 
{
   // execute code when button is pressed
   if(param.asInt()) 
   {
       int x=random_number; //generating random number
       Blynk.virtualWrite(V2,x); 
   } 
} 

Simple as that. Read the docs you need to understand this yourself, it’s the most basic of blynk functions. If you can’t learn and understand it then blynk unfortunately isn’t for you so go go go, read :slight_smile:

1 Like

Thanks, I know it’s something basic, I usually learn from examples but all I find is that “run” function, I don’t know what’s happening inside :sweat_smile:

@Khorne in it’s simplest form Blynk.run() keeps you connected to the Blynk server and the rest is handled by Blynk magic. But the Blynk magic is fully covered in the comprehensive docs and Sketch Builder etc.

Might seem a bit tedious but just work through some of the basic examples and ask yourself what each part of the code does. Any bits you are not sure of search the docs and if you are still unsure ask here.

@Costas Thanks, I was working on the project for long, multiple modules, functions…now I’m a bit out of time that’s why I couldn’t search deeply, Thank you guys.