BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Set dynamic value from app to code

Hi All,

I´m working in a servo motor project using a esp8266 board with blynk app where the task is triggered at a certain hour using the timer widget. I wish the delay value could be defined from the app, so the servo turns at a specific value. These could be done using the input value widget? remember that I´m using the timer widget also.
Another alternative to achieve the same result is to have a fixed delay value, such as 500, but from the blynk app I could select a multiplier so the task is repeated by x2 x3 etc.

Thanks a lot.

BLYNK_WRITE(V5)
{
servo.write(70); //85 is more like a speed instead of an angle.
delay(500);
servo.write(80); //Stop
}

Very simple to do. You would attach the numeric input widget to a virtual pin (say V6) and use the param.asInt() function to obtain the value and store it in a variable (which must be global rather than local).
You may wish to force a refresh of this value automatically by putting Blynk.syncVirtual(V6) at the beginning of your BLYNK_WRITE(V5) function.

However, you will quickly run in to issues using delays in this way within your Blynk sketch. You would be much better using a lambda timer.

A little searching of this forum will point you in the right direction for this.

Pete.