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

Best way to do?


#1

Dear Sirs,
I have something to implement and I am looking for the best way to do it. What I want: Using a blynk slider I will pass an int to a variable like how many seconds a relay will be on, activated. If the user press a start button then using a blynk timer ( simpletimer ) will be activated this relay on for the specified time and then off.
I am in trouble how to setup and call the timer.
Can you help me?

Thanks and Best Regards,
Mike Kranidis


#3

Hello, you can sent me PM here.


#5

OK I remember now… I will visit your site.


#6

Any idea or help regarding my question?


#7

Hi Mike,
Check this idea, (it’s working on the ESP01):

BLYNK_WRITE(V10)//      slider  from 1 to 10 seconds 
{
 int timerelayon = param.asInt(); 
 relay=timerelayon;
 Blynk.virtualWrite(V11, relay);
}

BLYNK_WRITE(V12)  // ON-OFF Switch mode
{
    if (param.asInt()==1) {
    digitalWrite(TestLED, HIGH); // set LED ON 
    led1.on();
    int relaysec = relay * 1000;
    timer.setTimeout(relaysec, resetRELAY);
    }
}

void resetRELAY(){
  digitalWrite(TestLED, LOW); // set LED OFF 
  Blynk.virtualWrite(V12, 0);
  led1.off();
}

Regards


#8

come on, just read the SimpleTimer docs…
At the button press handling routine just put the timer.setTimeout(sliderReceivedValue, callMeAfter);
and it should go! I think… int sliderReceivedValue; declared globally off course

edit: …and @psoro was first … :stuck_out_tongue:


#9

I even have a slightly more complicated example using a slider to adjust a timer for a variable speed servo… but same initial concept.


#10

@psoro @marvin7 @Gunner
First of all I would like to thank you guys for the ideas and the guidance. I can implemented now, the code part, is not so hard to me, the only concerning that is left: how to have possible using a value display widget, the countdown indication in order to have visualized the starting time in seconds down to zero when the time expired… ?

Thanks and Best Regards,
Mike Kranidis


#11

again BlynkTimer/SimpleTimer might help here:

Using the snippet provided by @psoro just add:

after
timer.setTimeout(relaysec, resetRELAY);
add this one:

timer.setTimer(1000, repeatUntilCountdown, relay);
countdown = relay;

and the routine:

int countdown; //globally

void repeatUntilCountdown () {
Blynk.virtualWrite (V11, countdown); //value widget from above
}

not tested, but now you have the idea :wink:


#12

Thanks @marvin7 I will try it when at home. Just one observation, I think we need a way to decrease the relay value possible in your repeatUntilCountdown function. As I can see, without this, you passing always the same value ( countdown = relay ; ) to this function…
Anyway I got the idea!

Thanks


#13

Yes, sure! Simply forgot about it :wink: so it will be:

void repeatUntilCountdown () {
Blynk.virtualWrite (V11, countdown); //value widget from above
countdown--;
}