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?
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();
}
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
@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 @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!