SimpleTimer reset timer
http://community.blynk.cc/t/simpletimer-reset-timer/6153
// SimpleTimer reset timer
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "461366bbw2e7d46b7b0wa0d4d785daw7c3b";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "74170287";
char pass[] = "24063173";
#define RELAY_PIN 2
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
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);
digitalWrite(RELAY_PIN, HIGH);
timer.setTimeout(20000L, turnRelayOff4);
}
void loop()
{
Blynk.run();
timer.run();
}
沒有留言:
張貼留言