Time input widget and eventor

That is part of the Over The Air update option for ESP (basicly uploding your sketch over the WiFi network instead of plugging it into USB) - see here for example C++ Blynk (Legacy) - Code Examples for Basic Tasks - #2 by Gunner Nothing to do with Timers :stuck_out_tongue:

Thanks again @Gunner I realize that I don’t need to code this in my case, 'cos I using ethernet shield :slight_smile: I’ll try to use this code to my project and see if it’s work for me.

This is my code, but still have issues, please help me!!!

#include <SoftwareSerial.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <TimeLib.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WidgetRTC.h>

#define BLYNK_PRINT Serial
#define echoPin 3 // Echo Pin
#define trigPin 5 // Trigger Pin
#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

BlynkTimer timer;            // define a timer for use by SimpleTimer library
WidgetRTC rtc;

int WM1=6;
int EncWV1=6;                // Global variable used in Slider widget and runEveryMinute()
int ApagWV1=6;                // Global variable used in Slider widget and runEveryMinute()

int WM2=7;
int EncWV2=7;                // Global variable used in Slider widget and runEveryMinute()
int ApagWV2=7;                // Global variable used in Slider widget and runEveryMinute()
int x, y, z, a;

int CounterOn = 0;
int CounterOff = 0;
int ledStatus = 0;

int CounterOn2 = 0;
int CounterOff2 = 0;
int ledStatus2 = 0;

int AutoRelleno=8;
int SumpLamp=9;

float Celsius = 0;
float Fahrenheit = 0;

char auth[] = "c046b3f28da144598e5119d4d2cfb74d";

long duration, distance; // Duration used to calculate distance

int NivelMax=0;
int NivelMin=0;

char currentTime[9];
char startTime[9];
char stopTime[9];
int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;


BLYNK_CONNECTED() 
  {
    Blynk.syncAll();  // Synchronize hardware with App widgets when connected
    Blynk.syncVirtual(V10); //  Synchronize Time Input Widget when connected 
  }

BLYNK_WRITE(V0) 
  {   // add a slider to your project on V0 range 0 to 120 (seconds)
    x = param.asInt();  // set variable as Slider value
    EncWV1 = x;
    Serial.print("Wave Maker 1 On Timer set to: ");
    Serial.print(EncWV1);
    Serial.println(" seconds");
  }

BLYNK_WRITE(V1) 
  {   // add a slider to your project on V1 range 0 to 120 (seconds)
    y = param.asInt();  // set variable as Slider value 
    ApagWV1 = y;  
    Serial.print("Wave Maker 1 Off Timer set to: ");
    Serial.print(ApagWV1);
    Serial.println(" seconds");
  }

BLYNK_WRITE(V2) 
  {   // add a slider to your project on V0 range 0 to 120 (seconds)
    z = param.asInt();  // set variable as Slider value
    EncWV2 = z;
    Serial.print("Wave Maker 2 On Timer set to: ");
    Serial.print(EncWV2);
    Serial.println(" seconds");
  }

BLYNK_WRITE(V3) 
  {   // add a slider to your project on V1 range 0 to 120 (seconds)
    a = param.asInt();  // set variable as Slider value 
    ApagWV2 = a;  
    Serial.print("Wave Maker 2 Off Timer set to: ");
    Serial.print(ApagWV2);
    Serial.println(" seconds");
  }

BLYNK_WRITE(V7) 
  {   // add a slider to your project on V1 range 0 to 120 (seconds)
    NivelMax = param.asInt();  // set variable as Slider value  
    Serial.print("Encender bomba en: ");
    Serial.print(NivelMax);
    Serial.println(" segundos");
  }

BLYNK_WRITE(V8) 
  {   // add a slider to your project on V0 range 0 to 120 (seconds)
    NivelMin = param.asInt();  // set variable as Slider value
    
    Serial.print("Encender bomba en: ");
    Serial.print(NivelMin);
    Serial.println(" segundos");
  }


BLYNK_WRITE(V10) {  // Called whenver setting Time Input Widget
  TimeInputParam t(param);
  SThour = t.getStartHour();
  STmin = t.getStartMinute();
  STsec = t.getStartSecond();
  SPhour = t.getStopHour();
  SPmin = t.getStopMinute();
  SPsec = t.getStopSecond();
}

void led_control()
  {
    //First Wave Maker
      
    if ((CounterOn > 0) && (ledStatus == 0))
      {
        digitalWrite(WM1,HIGH);   //write to pin to turn the LED on.
        Serial.print("Wave Maker 1: ON\n");
        ledStatus = 1;
        CounterOff = 0;
      }
   
  if ((CounterOn > 0) && (ledStatus == 1))
      {
      CounterOn = (CounterOn - 1);
      }
      
  if ((CounterOff == 0) && (CounterOn == 0) && (ledStatus == 1))
    {
      CounterOff = ApagWV1;
    }

  if ((CounterOff > 0) && (ledStatus == 1))
  {
      digitalWrite(WM1,LOW);   //write to pin to turn the LED off.
      Serial.print("Wave Maker 1: OFF\n");
      ledStatus = 0;
      CounterOn = 0;
   }
   
  if ((CounterOff > 0) && (ledStatus == 0))
      {
      CounterOff = (CounterOff - 1);
      }
      
  if ((CounterOff == 0) && (CounterOn == 0) && (ledStatus == 0))
    {
      CounterOn = EncWV1+1;
    }

  //Second Wave Maker

  if ((CounterOn2 > 0) && (ledStatus2 == 0))
      {
        digitalWrite(WM2,HIGH);   //write to pin to turn the LED on.
        Serial.print("Wave Maker 2: ON\n");
        ledStatus2 = 1;
        CounterOff2 = 0;
      }
   
  if ((CounterOn2 > 0) && (ledStatus2 == 1))
      {
      CounterOn2 = (CounterOn2 - 1);
      }
      
  if ((CounterOff2 == 0) && (CounterOn2 == 0) && (ledStatus2 == 1))
    {
      CounterOff2 = ApagWV2;
    }

  if ((CounterOff2 > 0) && (ledStatus2 == 1))
  {
      digitalWrite(WM2,LOW);   //write to pin to turn the LED off.
      Serial.print("Wave Maker 2: OFF\n");
      ledStatus2 = 0;
      CounterOn2 = 0;
   }
   
  if ((CounterOff2 > 0) && (ledStatus2 == 0))
      {
      CounterOff2 = (CounterOff2 - 1);
      }
      
  if ((CounterOff2 == 0) && (CounterOn2 == 0) && (ledStatus2 == 0))
    {
      CounterOn2 = EncWV2+1;
    }

}

void MeasureCm()
  {
   /* The following trigPin/echoPin cycle is used to determine the
   distance of the nearest object by bouncing soundwaves off of it. */ 
  
       
   digitalWrite(trigPin, LOW); 
   delayMicroseconds(2); 
  
   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10); 
       
   digitalWrite(trigPin, LOW);
   duration = pulseIn(echoPin, HIGH);
       
   //Calculate the distance (in cm) based on the speed of sound.
   distance = duration/58.2;
  
   Serial.print("Distance: ");
   Serial.println(distance); 
   Blynk.virtualWrite(4,distance);   

   if (distance>NivelMax)
     {
      digitalWrite(AutoRelleno, HIGH);
      WidgetLED AR(5); //means you need to have LED on app configured on virtual pin 1.
      AR.on();
      Serial.print("Bomba de Autorelleno Encendida");
     }
   if (distance<NivelMin)
     {
      digitalWrite(AutoRelleno, LOW);
      WidgetLED AR(5); //means you need to have LED on app configured on virtual pin 5.
      AR.off();
      Serial.print("Bomba de Autorelleno Apagada");
     }
   }

void Temperatura()
  {
    sensors.requestTemperatures();
    Celsius = sensors.getTempCByIndex(0);
    Blynk.virtualWrite(6,Celsius);
    Serial.print("Temperatura: ");
    Serial.print(Celsius);
    Serial.print(" C");
  }

void EncendidoSumpLamp() {  // call with timer every 30 seconds or so
  // Get RTC time  
  sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
  Serial.print("Current Time: ");
  Serial.println(currentTime);

  // Get Time Input Widget time
  sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
  Serial.print("Start Time: ");
  Serial.println(startTime);

  sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
  Serial.print("Stop Time: ");
  Serial.println(startTime);
  
  if (hour() == SThour) {
    if (minute() == STmin) {
      Serial.println("Doing something now");
      digitalWrite(SumpLamp, HIGH); // Turn ON built-in LED
    } else if (minute() < STmin) {
      Serial.println("Will do something");
    } else if (minute() > STmin) {
      Serial.println("Did something");
    } else {
      Serial.println("Clueless");
    }
  }

  if (hour() == SPhour) {
    if (minute() == SPmin) {
      Serial.println("Stopping something now");
      digitalWrite(SumpLamp, LOW); // Turn OFF built-in LED
    } else if (minute() < SPmin) {
      Serial.println("Will stop something");
    } else if (minute() > SPmin) {
      Serial.println("Stopped something");
    } else {
      Serial.println("Clueless");
    }
  }
  Serial.println("----------");
}


void setup()
{
  if (EncWV1== 0)
  {
    EncWV1=1;
  }
  if (ApagWV1== 0)
  {
    ApagWV1=1;
  }

  sensors.begin();
  Serial.begin(9600); 
  Blynk.begin(auth);
  rtc.begin();
  
  CounterOn = EncWV1+1;
  // run timer every 1 second to check for led On/Off action
  timer.setInterval(1000L, led_control);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(12, OUTPUT);
     
  timer.setInterval(1000L, MeasureCm);
  timer.setInterval(20000L, Temperatura);
  timer.setInterval(1000L, EncendidoSumpLamp); // EncendidoSumpLamp Time Check     
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates Timer to ensure the timer keeps running  
} 

Works fine for a time, then wen the advanced input timmer run out it crash everything and lost conection.