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