SimpleTimer Help

I’m using SimpleTimer Timeout function to open/close a relay. The problem I’m having is the 15 second timer doesn’t reset. For instance if I tigger V6, wait 5 seconds, trigger V7, wait 5 seconds, and trigger V6 again then V6 will only stay active for 5 more seconds not another 15 seconds like I want. I tried to get the reset or disable function to work but can’t seem to do it. Any suggestions? Thanks


BLYNK_WRITE(V6) { 
  Serial.println("Relay Closing...");
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  timer.setTimeout(15000, CloseRelay);
}

void CloseRelay() {
    digitalWrite(5, HIGH);
    Blynk.virtualWrite(V6, HIGH);
    Serial.println("Relay Closed");
}

BLYNK_WRITE(V7) { 
  Serial.println("Relay Opening...");
  digitalWrite(5, HIGH);
  digitalWrite(4, LOW);
  timer.setTimeout(15000, OpenRelay);
}

void OpenRelay() {
    digitalWrite(4, HIGH);
    Blynk.virtualWrite(V7, HIGH);
    Serial.println("Relay Opened");

You should really be using Blynk timer rather than Simple timer. They’re basically the same, but there’s a buy in Simple timers regarding the timer ID of the first timer that’s created, which is fixed in the Blynk version. The Blynk version also has some improvements such as allowing more timer instances per timer object (16) and code to prevent Blynk server flooding.

You need to capture the timer ID, then use that ID to either disable, delete or restart when the V6 and V7 buttons are pressed.

https://playground.arduino.cc/Code/SimpleTimer/#F_SimpleTimer

Pete.