[SOLVED] Triggered cycle counter

SimpleTimer to the rescue!

void actionRelays(){
  relay1_ON(); // turn on relay1
  timer.setTimeout(2000, relay2_ON); // delay 2sec then turn on relay2
  timer.setTimeout(15000, relays_OFF); // delay 15sec from first action and turn off both relays
}

void relay1_ON(){
  digitalWrite(relay1,HIGH); // turn on relay1
  Blynk.virtualWrite(V10, 255); // turn on an LED widget (optional)
}

void relay2_ON(){
  digitalWrite(relay2,HIGH); // turn on relay2
  Blynk.virtualWrite(V20, 255); // turn on an LED widget (optional)
}

void relays_OFF(){
  digitalWrite(relay1,LOW); // turn off relay1
  digitalWrite(relay2,LOW); // turn off relay2
  Blynk.virtualWrite(V10, 0); // turn off an LED widget (optional)
  Blynk.virtualWrite(V20, 0); // turn off an LED widget (optional)
}

Run actionRelays() anywhere in your code and it will automatically do the timed sequence without blocking.

1 Like