SimpleTimer reset timer

As a newbie on BLYNK forum I would like to ask a question about timers.
I try to use SimpleTimer library to run a short time timer to control a relay.
This works fine but…
When I try to add multiple Buttons with different pre-set timers I run in to problem.
I need a function that kill/cancel the running timer if press a cancel button.
Also if I hit another pre-set button it should cancel the running timer and start a new.

Code looks like this right now.

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include < SPI.h>
#include < ESP8266WiFi.h>
#include < BlynkSimpleEsp8266.h>
#include < SimpleTimer.h>
SimpleTimer timer;
#define RELAY_PIN D0
char auth[] = "830f4ea4089d4f9e818a01bdd8f34be4";
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "Timber", "greggan12", "192.168.1.10", 8442);
}

void turnRelayOff1() {
    digitalWrite(RELAY_PIN, LOW);
    Blynk.virtualWrite(V1, LOW);
    Blynk.virtualWrite(V5, LOW);
    Serial.println("Relay disabled"); 
}void turnRelayOff2() {
    digitalWrite(RELAY_PIN, LOW);
    Blynk.virtualWrite(V2, LOW);
    Blynk.virtualWrite(V6, LOW);
    Serial.println("Relay disabled"); 
}void turnRelayOff3() {
    digitalWrite(RELAY_PIN, LOW);
    Blynk.virtualWrite(V3, LOW);
    Blynk.virtualWrite(V7, LOW);
    Serial.println("Relay disabled"); 
}void turnRelayOff4() {
    digitalWrite(RELAY_PIN, LOW);
    Blynk.virtualWrite(V4, LOW);
    Blynk.virtualWrite(V8, LOW);
    Serial.println("Relay disabled");                                               
}
BLYNK_WRITE(V1){
  if (RELAY_PIN, LOW) 
  Serial.println("Relay enabled");
  Blynk.virtualWrite(V5, 255);
  digitalWrite(RELAY_PIN, HIGH);
  timer.setTimeout(1000L, turnRelayOff1);
}
BLYNK_WRITE(V2){
  if (RELAY_PIN, LOW) 
  Serial.println("Relay enabled");
  Blynk.virtualWrite(V6, 255);
  digitalWrite(RELAY_PIN, HIGH);
  timer.setTimeout(5000L, turnRelayOff2);
}
BLYNK_WRITE(V3){ 
  if (RELAY_PIN, LOW);
  Serial.println("Relay enabled");
  Blynk.virtualWrite(V7, 255);
  digitalWrite(RELAY_PIN, HIGH);
  timer.setTimeout(10000L, turnRelayOff3);
}
BLYNK_WRITE(V4){ 
  if (RELAY_PIN, HIGH);
  Serial.println("Relay disabled");
  Blynk.virtualWrite(V8, 255);
  timer.setTimeout(50L, turnRelayOff4);
}
void loop()
{
  Blynk.run();
  timer.run();
}

Please look into SimpleTimer libraary examples.

Thank’s for that advice.
However I can’t get a clue that is easy enough for stupid me to follow :slight_smile:

You can’t use timer.setTimeout(1000L, turnRelayOff1); in the loop. Please check the example and see how Timer is used.

  1. you define the timer in the setup
  2. you define what should happen in the defined interval
  3. you call the timer in the void loop

Hi @Greggan

I’m interested in doing the same thing but using a variable from the slider widget http://community.blynk.cc/t/nodemcu-v1-using-blynk/12683/25? did you end up getting this working?

@AusUser5 take a look at this thread.
How to change SimpleTimer timer interval remotely?

Please avoid thread necromancy :slight_smile:
Rather start a new one. Hit me up with a message if the procedure in the link is not understandable enough.