BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Time problem on my project


#1

Hi guys, i got big troubles with my project and i really need your help, i’m goin’ crazy!!
i’m creating a small greenhouse with a light control and a water pump control. i’m using a local server.

To create the code i’ve used an old project found here called “4 way control relay”. untill i’ve used this to control only one relay, everythig was ok. the problems started when i’ve changed the code to introduce a second relay control.

If i reset the board and set the time for on and off to check it, everything works, but after 7-8 hours when the relay has to start again, never start. i can’t understand where is the error.
here’s code and screenshots.

Please help me!!


#4

sorry but i have trouble uploading my code…


#5

OMG… you need to put your code in proper formatting…


#6

enclosure it with ``` (If you had read the “how to post” you would know) Edit your first post and delete the others… and with a correct formatted code maybe someone can help you… after seeing your code published that way … everyone will lose the impulse to read it


#7

Take a look at this project as well Simple 4 relay irrigation scheduler


#8

Please repost your code properly… Thank you.

Blynk - FTFC


#9

ok, I had not read the post …,i’m really sorry guys.
here is the code:

#define BLYNK_PRINT Serial

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <DHT.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

#define DHTPIN 4
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

#define TRIGGER 1
#define ECHO    5

#define server "192.168.178.55"
#define LAMP 6 
#define PUMP 8 
char Date[16];
char Time[16];
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
long startsecondswd;            // weekday start time in seconds
long stopsecondswd;             // weekday stop  time in seconds
long nowseconds;                // time now in seconds
bool isFirstConnect = true;

String displaycurrenttime;
int manualLAMP=0;
int oldstatusLAMP;
int manualPUMP=0;
int oldstatusPUMP;

int stepone;
int steptwo;
int stepthree;
int uptoyou;

int everyday;
int fourweek;
int twoweek;
int oneweek;

// the timer object
BlynkTimer timer;
WidgetRTC rtc;
WidgetTerminal terminalLAMP(V23);
WidgetTerminal terminalPUMP(V43);

float humidity, temp_f;  // Values read from sensor

//#define W5100_CS  10
//#define SDCARD_CS 4

BLYNK_WRITE(V15) //ultrasonic
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

  // process received value
}

void setup()
{
  pinMode(LAMP, OUTPUT);
  pinMode(PUMP, OUTPUT);
  pinMode(TRIGGER, OUTPUT);
  pinMode(ECHO, INPUT);
  digitalWrite(LAMP, LOW); // set LED OFF
  digitalWrite(PUMP, LOW); // set LED OFF
  Serial.begin(9600); // Debug console
  Serial.println("Starting");
  Blynk.begin(auth, server, 8080);
  
  int mytimeout = millis() / 1000;
  while (Blynk.connect() == false) { // try to connect to server for 10 seconds
    if((millis() / 1000) > mytimeout + 8){ // try local server if not connected within 9 seconds
       break;
    }
  }
  rtc.begin();
  timer.setInterval(10000L, activetoday);  // check every 10 SECONDS if schedule should run today 
  timer.setInterval(30000L, reconnectBlynk);  // check every 30s if still connected to server 
  timer.setInterval(5000L, clockvalue);  // check value for time
  timer.setInterval(1000, sendData);
}

BLYNK_CONNECTED() {
if (isFirstConnect) {
  Blynk.syncAll();
  Blynk.notify("TIMER STARTING!!!!");
isFirstConnect = false;
}
}

void clockvalue() // Digital clock display of the time
{
 int gmthour = hour();
  if (gmthour == 24){
     gmthour = 0;
  }
  String displayhour =   String(gmthour, DEC);
  int hourdigits = displayhour.length();
  if(hourdigits == 1){
    displayhour = "0" + displayhour;
  }
  String displayminute = String(minute(), DEC);
  int minutedigits = displayminute.length();  
  if(minutedigits == 1){
    displayminute = "0" + displayminute;
  }  

  displaycurrenttime = "                                          Clock:  " + displayhour + ":" + displayminute + "                                ";
  Blynk.setProperty(V23,"label", displaycurrenttime);  
}

void activetoday(){        // check if schedule should run today
  if(year() != 1970){

   if (stepone==1) {  
    Blynk.syncVirtual(V24); // sync timeinput widget  
   }
   if (steptwo==1) { 
    Blynk.syncVirtual(V26); // sync timeinput widget  
   }
   if (stepthree==1) { 
    Blynk.syncVirtual(V28); // sync timeinput widget  
   }
   if (uptoyou==1) { 
    Blynk.syncVirtual(V30); // sync timeinput widget  
   }
   if (everyday==1) {  
    Blynk.syncVirtual(V44); // sync timeinput widget  
   }
   if (fourweek==1) { 
    Blynk.syncVirtual(V46); // sync timeinput widget  
   }
   if (twoweek==1) { 
    Blynk.syncVirtual(V48); // sync timeinput widget  
   }
   if (oneweek==1) { 
    Blynk.syncVirtual(V50); // sync timeinput widget  
   }
  }
}

void checklastbuttonpressedLAMP (){
    if(stepone==1){ oldstatusLAMP=1; }
    if(steptwo==1){ oldstatusLAMP=2; }
    if(stepthree==1){ oldstatusLAMP=3; }
    if(uptoyou==1){ oldstatusLAMP=4; }
    if((stepone==0)&&(steptwo==0)&&(stepthree==0)&&(uptoyou==0)){ oldstatusLAMP=5; } 
}

void checklastbuttonpressedPUMP (){    
    if(everyday==1){ oldstatusPUMP=1; }
    if(fourweek==1){ oldstatusPUMP=2; }
    if(twoweek==1){ oldstatusPUMP=3; }
    if(oneweek==1){ oldstatusPUMP=4; }
    if((everyday==0)&&(fourweek==0)&&(twoweek==0)&&(oneweek==0)){ oldstatusPUMP=5; }  
}

void restorelastbuttonpressedLAMP (){
    if(oldstatusLAMP==1){ stepone=1; Blynk.virtualWrite(V25, 1);}
    if(oldstatusLAMP==2){ steptwo=1; Blynk.virtualWrite(V27, 1);}
    if(oldstatusLAMP==3){ stepthree=1; Blynk.virtualWrite(V29, 1);}
    if(oldstatusLAMP==4){ uptoyou=1; Blynk.virtualWrite(V31, 1);}   
    if(oldstatusLAMP==5){ 
      stepone=0; 
      steptwo=0;
      stepthree=0;
      uptoyou=0;
      Blynk.virtualWrite(V25, 0);
      Blynk.virtualWrite(V27, 0);
      Blynk.virtualWrite(V29, 0);
      Blynk.virtualWrite(V31, 0);
      }
}

void restorelastbuttonpressedPUMP (){
    if(oldstatusPUMP==1){ everyday=1; Blynk.virtualWrite(V45, 1);}
    if(oldstatusPUMP==2){ fourweek=1; Blynk.virtualWrite(V47, 1);}
    if(oldstatusPUMP==3){ twoweek=1; Blynk.virtualWrite(V49, 1);}
    if(oldstatusPUMP==4){ oneweek=1; Blynk.virtualWrite(V51, 1);}   
    if(oldstatusPUMP==5){ 
      everyday=0; 
      fourweek=0;
      twoweek=0;
      oneweek=0;
      Blynk.virtualWrite(V45, 0);
      Blynk.virtualWrite(V47, 0);
      Blynk.virtualWrite(V49, 0);
      Blynk.virtualWrite(V51, 0);
      }
 } 


BLYNK_WRITE(V21)  // Manual/Auto selection LAMP
{
  if (param.asInt()==1) {
    manualLAMP=1;
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println("Manual MODE is ON");
    terminalLAMP.println("Press ON/OFF button if required");
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.flush();

    checklastbuttonpressedLAMP ();
  
    stepthree=0;
    uptoyou=0;
    stepone=0;
    steptwo=0;
    Blynk.virtualWrite(V25, 0);
    Blynk.virtualWrite(V27, 0);
    Blynk.virtualWrite(V29, 0);
    Blynk.virtualWrite(V31, 0);
    
  } else {
    restorelastbuttonpressedLAMP ();
    manualLAMP=0;
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println("Manual MODE is OFF");
    terminalLAMP.println("Auto MODE restored from last status");
    terminalLAMP.println("Wait for update (10 seconds as maximum)");
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.flush();
}
}

BLYNK_WRITE(V41)  // Manual/Auto selection PUMP
{
  if (param.asInt()==1) {
    manualPUMP=1;
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println("Manual MODE is ON");
    terminalPUMP.println("Press ON/OFF button if required");
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.flush();

    checklastbuttonpressedPUMP ();
  
    everyday=0;
    fourweek=0;
    twoweek=0;
    oneweek=0;
    Blynk.virtualWrite(V45, 0);
    Blynk.virtualWrite(V47, 0);
    Blynk.virtualWrite(V49, 0);
    Blynk.virtualWrite(V51, 0);
    
  } else {
    restorelastbuttonpressedPUMP ();
    manualPUMP=0;
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println("Manual MODE is OFF");
    terminalPUMP.println("Auto MODE restored from last status");
    terminalPUMP.println("Wait for update (10 seconds as maximum)");
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.flush();
}
}

void resetterminalLAMP()
{
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println("New MODE has been selected");
    terminalLAMP.println("Wait for update (10 seconds as maximum)");
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.flush();
}

void resetterminalPUMP()
{
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println("New MODE has been selected");
    terminalPUMP.println("Wait for update (10 seconds as maximum)");
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.flush();
}
void resetManualLAMP()
{
Blynk.virtualWrite(V21, 0);   //Turn OFF Manual Mode Widget
Blynk.virtualWrite(V22, 0);   //Turn OFF Button Widget Device
digitalWrite(LAMP, LOW); // set LED OFF
}

void resetManualPUMP()
{
Blynk.virtualWrite(V41, 0);   //Turn OFF Manual Mode Widget
Blynk.virtualWrite(V42, 0);   //Turn OFF Button Widget Device
digitalWrite(PUMP, LOW); // set LED OFF
}

BLYNK_WRITE(V22)  // ON-OFF Manual LAMP
{
    if (param.asInt()==1) {  // boton encendido  
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println("Manual MODE is ON");
    terminalLAMP.println("Press ON/OFF button if required");
    terminalLAMP.println("Device is ON");
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.flush();
    
        if (manualLAMP==0){  //está en modo automático     
         checklastbuttonpressedLAMP ();
         manualLAMP=1;
         stepone=0;
         steptwo=0;
         stepthree=0;
         uptoyou=0;
         Blynk.virtualWrite(V21, 1);
         Blynk.virtualWrite(V25, 0);
         Blynk.virtualWrite(V27, 0);
         Blynk.virtualWrite(V29, 0);
         Blynk.virtualWrite(V21, 0);
         digitalWrite(LAMP, HIGH); // set LED ON 
         Blynk.virtualWrite(V22, 1);   //Turn ON Button Widget
         
         } else {             //está en modo manual 
         stepone=0;
         steptwo=0;
         stepthree=0;
         uptoyou=0;
         Blynk.virtualWrite(V21, 1);
         Blynk.virtualWrite(V25, 0);
         Blynk.virtualWrite(V27, 0);
         Blynk.virtualWrite(V29, 0);
         Blynk.virtualWrite(V31, 0);
         digitalWrite(LAMP, HIGH); // set LED ON 
         Blynk.virtualWrite(V22, 1);   //Turn ON Button Widget
         }                           
    }else {
      
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.println("Manual MODE is ON");
    terminalLAMP.println("Press ON/OFF button if required");
    terminalLAMP.println("Device is OFF");
    terminalLAMP.println();
    terminalLAMP.println();
    terminalLAMP.flush();

        if (manualLAMP==0){      //modo automático
         checklastbuttonpressedLAMP ();
         manualLAMP=1;
         stepone=0;
         steptwo=0;
         stepthree=0;
         uptoyou=0;
         Blynk.virtualWrite(V21, 1);
         Blynk.virtualWrite(V25, 0);
         Blynk.virtualWrite(V27, 0);
         Blynk.virtualWrite(V29, 0);
         Blynk.virtualWrite(V31, 0);
         digitalWrite(LAMP, LOW); // set LED OFF
         Blynk.virtualWrite(V22, 0);   //Turn OFF Button Widget
         } else {  
         stepone=0;
         steptwo=0;
         stepthree=0;
         uptoyou=0;   
         Blynk.virtualWrite(V21, 1);
         Blynk.virtualWrite(V25, 0);
         Blynk.virtualWrite(V27, 0);
         Blynk.virtualWrite(V29, 0);
         Blynk.virtualWrite(V31, 0);
         digitalWrite(LAMP, LOW); // set LED OFF
         Blynk.virtualWrite(V22, 0);   //Turn OFF Button Widget
         }  
         }
}

BLYNK_WRITE(V42)  // ON-OFF Manual PUMP
{
    if (param.asInt()==1) {  // boton encendido  
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println("Manual MODE is ON");
    terminalPUMP.println("Press ON/OFF button if required");
    terminalPUMP.println("Device is ON");
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.flush();
    
        if (manualPUMP==0){  //está en modo automático     
         checklastbuttonpressedPUMP ();
         manualPUMP=1;
         everyday=0;
         fourweek=0;
         twoweek=0;
         oneweek=0;
         Blynk.virtualWrite(V41, 1);
         Blynk.virtualWrite(V45, 0);
         Blynk.virtualWrite(V47, 0);
         Blynk.virtualWrite(V49, 0);
         Blynk.virtualWrite(V51, 0);
         digitalWrite(PUMP, HIGH); // set LED ON 
         Blynk.virtualWrite(V42, 1);   //Turn ON Button Widget
         
         } else {             //está en modo manual 
         everyday=0;
         fourweek=0;
         twoweek=0;
         oneweek=0;
         Blynk.virtualWrite(V41, 1);
         Blynk.virtualWrite(V45, 0);
         Blynk.virtualWrite(V47, 0);
         Blynk.virtualWrite(V49, 0);
         Blynk.virtualWrite(V51, 0);
         digitalWrite(PUMP, HIGH); // set LED ON 
         Blynk.virtualWrite(V42, 1);   //Turn ON Button Widget
         }                           
    }else {
      
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.println("Manual MODE is ON");
    terminalPUMP.println("Press ON/OFF button if required");
    terminalPUMP.println("Device is OFF");
    terminalPUMP.println();
    terminalPUMP.println();
    terminalPUMP.flush();

        if (manualPUMP==0){      //modo automático
         checklastbuttonpressedPUMP ();
         manualPUMP=1;
         everyday=0;
         fourweek=0;
         twoweek=0;
         oneweek=0;
         Blynk.virtualWrite(V41, 1);
         Blynk.virtualWrite(V45, 0);
         Blynk.virtualWrite(V47, 0);
         Blynk.virtualWrite(V49, 0);
         Blynk.virtualWrite(V51, 0);
         digitalWrite(PUMP, LOW); // set LED OFF
         Blynk.virtualWrite(V42, 0);   //Turn OFF Button Widget
         } else {  
         everyday=0;
         fourweek=0;
         twoweek=0;
         oneweek=0;   
         Blynk.virtualWrite(V41, 1);
         Blynk.virtualWrite(V45, 0);
         Blynk.virtualWrite(V47, 0);
         Blynk.virtualWrite(V49, 0);
         Blynk.virtualWrite(V51, 0);
         digitalWrite(PUMP, LOW); // set LED OFF
         Blynk.virtualWrite(V42, 0);   //Turn OFF Button Widget
         }  
         }
}

BLYNK_WRITE(V25)  // Step One selected LAMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalLAMP);
    timer.setTimeout(50, resetManualLAMP);
    timer.setTimeout(50, checklastbuttonpressedLAMP);
    stepone=1;
    steptwo=0;
    stepthree=0;
    uptoyou=0;
    Blynk.virtualWrite(V27, 0);
    Blynk.virtualWrite(V29, 0);
    Blynk.virtualWrite(V31, 0);
  } else {
    stepone=0;
}
}

BLYNK_WRITE(V45)  // everyday selected PUMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalPUMP);
    timer.setTimeout(50, resetManualPUMP);
    timer.setTimeout(50, checklastbuttonpressedPUMP);
    everyday=1;
    fourweek=0;
    twoweek=0;
    oneweek=0;
    Blynk.virtualWrite(V47, 0);
    Blynk.virtualWrite(V49, 0);
    Blynk.virtualWrite(V51, 0);
  } else {
    everyday=0;
}
}

BLYNK_WRITE(V27)  // Step Two selected LAMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalLAMP);
    timer.setTimeout(50, resetManualLAMP);
    timer.setTimeout(50, checklastbuttonpressedLAMP);
    stepone=0;
    steptwo=1;
    stepthree=0;
    uptoyou=0;
    Blynk.virtualWrite(V25, 0);
    Blynk.virtualWrite(V29, 0);
    Blynk.virtualWrite(V31, 0);
  } else {
    steptwo=0;
}
}

BLYNK_WRITE(V47)  // fourweek selected PUMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalPUMP);
    timer.setTimeout(50, resetManualPUMP);
    timer.setTimeout(50, checklastbuttonpressedPUMP);
    everyday=0;
    fourweek=1;
    twoweek=0;
    oneweek=0;
    Blynk.virtualWrite(V45, 0);
    Blynk.virtualWrite(V49, 0);
    Blynk.virtualWrite(V51, 0);
  } else {
    fourweek=0;
}
}

BLYNK_WRITE(V29)  // Step Three selected LAMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalLAMP);
    timer.setTimeout(50, resetManualLAMP);
    timer.setTimeout(50, checklastbuttonpressedLAMP);
    stepone=0;
    steptwo=0;
    stepthree=1;
    uptoyou=0; 
    Blynk.virtualWrite(V25, 0);
    Blynk.virtualWrite(V27, 0);
    Blynk.virtualWrite(V31, 0);
  } else {
    stepthree=0;
}
}

BLYNK_WRITE(V49)  // twoweek selected PUMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalPUMP);
    timer.setTimeout(50, resetManualPUMP);
    timer.setTimeout(50, checklastbuttonpressedPUMP);
    everyday=0;
    fourweek=0;
    twoweek=1;
    oneweek=0; 
    Blynk.virtualWrite(V45, 0);
    Blynk.virtualWrite(V47, 0);
    Blynk.virtualWrite(V51, 0);
  } else {
    twoweek=0;
}
}


BLYNK_WRITE(V31)  // Up to you selected LAMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalLAMP);
    timer.setTimeout(50, resetManualLAMP);
    timer.setTimeout(50, checklastbuttonpressedLAMP);
    stepone=0;
    steptwo=0;
    stepthree=0;
    uptoyou=1;
    Blynk.virtualWrite(V25, 0);
    Blynk.virtualWrite(V27, 0);
    Blynk.virtualWrite(V29, 0);
  } else {
    uptoyou=0;
}
}

BLYNK_WRITE(V51)  // oneweek selected PUMP
{
  if (param.asInt()==1) {
    timer.setTimeout(50, resetterminalPUMP);
    timer.setTimeout(50, resetManualPUMP);
    timer.setTimeout(50, checklastbuttonpressedPUMP);
    everyday=0;
    fourweek=0;
    twoweek=0;
    oneweek=1;
    Blynk.virtualWrite(V45, 0);
    Blynk.virtualWrite(V47, 0);
    Blynk.virtualWrite(V49, 0);
  } else {
    oneweek=0;
}
}

BLYNK_WRITE(V24)//Step One LAMP
{  
  if (stepone==1) {         
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalLAMP.print("M-F Checked schedule at: ");
    terminalLAMP.println(Time);
    terminalLAMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
      dayadjustment =  6; // needed for Sunday, Time library is day 1 and Blynk is day 7
    }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){ //Time library starts week on Sunday, Blynk on Monday
    terminalLAMP.println("Step One ACTIVE today");
    terminalLAMP.flush();
    if (t.hasStartTime())
    {
      terminalLAMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
    }
    if (t.hasStopTime())
    {
      terminalLAMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
    }
    // Display timezone details, for information purposes only 
    terminalLAMP.println(String("Time zone: ") + t.getTZ()); 
    terminalLAMP.flush();
  
     for (int i = 1; i <= 7; i++) {  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
        if (t.isWeekdaySelected(i)) {
        terminalLAMP.println(String("Day ") + i + " is selected");
        terminalLAMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalLAMP.print("Step One STARTED at");
      terminalLAMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
      if(nowseconds <= startsecondswd + 90){    // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(LAMP, HIGH); // set LED ON
        Blynk.virtualWrite(V22, 1);
        // code here to switch the relay ON
      }      
    }
    else{
      terminalLAMP.println("Step One Device NOT STARTED today");
      terminalLAMP.flush();
   
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    if(nowseconds >= stopsecondswd){
      digitalWrite(LAMP, LOW); // set LED OFF
      Blynk.virtualWrite(V22, 0);
      terminalLAMP.print("Step One STOPPED at");
      terminalLAMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
      if(nowseconds <= stopsecondswd + 90){   // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(LAMP, LOW); // set LED OFF
        Blynk.virtualWrite(V22, 0);
        // code here to switch the relay OFF
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(LAMP, HIGH); // set LED ON    test
        Blynk.virtualWrite(V22, 1);
        terminalLAMP.println("Step One is ON");
        terminalLAMP.flush();
      
      }          
    }
  }
  else{
    terminalLAMP.println("Step One INACTIVE today");
    terminalLAMP.flush();    
  }
  terminalLAMP.println();
}
}

#10
BLYNK_WRITE(V44) //everyday PUMP
{  
  if (everyday==1) {         
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalPUMP.print("M-F Checked schedule at: ");
    terminalPUMP.println(Time);
    terminalPUMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
      dayadjustment =  6; // needed for Sunday, Time library is day 1 and Blynk is day 7
    }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){ //Time library starts week on Sunday, Blynk on Monday
    terminalPUMP.println("Everyday ACTIVE today");
    terminalPUMP.flush();
    if (t.hasStartTime())
    {
      terminalPUMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
    }
    if (t.hasStopTime())
    {
      terminalPUMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
    }
    // Display timezone details, for information purposes only 
    terminalPUMP.println(String("Time zone: ") + t.getTZ()); 
    terminalPUMP.flush();
  
     for (int i = 1; i <= 7; i++) {  // Process weekdays (1. Mon, 2. Tue, 3. Wed, ...)
        if (t.isWeekdaySelected(i)) {
        terminalPUMP.println(String("Day ") + i + " is selected");
        terminalPUMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalPUMP.print("Everyday STARTED at");
      terminalPUMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
      if(nowseconds <= startsecondswd + 90){    // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(PUMP, HIGH); // set LED ON
        Blynk.virtualWrite(V42, 1);
        // code here to switch the relay ON
      }      
    }
    else{
      terminalPUMP.println("Everyday Device NOT STARTED today");
      terminalPUMP.flush();
   
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    if(nowseconds >= stopsecondswd){
      digitalWrite(PUMP, LOW); // set LED OFF
      Blynk.virtualWrite(V42, 0);
      terminalPUMP.print("Everyday STOPPED at");
      terminalPUMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
      if(nowseconds <= stopsecondswd + 90){   // 90s on 60s timer ensures 1 trigger command is sent
        digitalWrite(PUMP, LOW); // set LED OFF
        Blynk.virtualWrite(V42, 0);
        // code here to switch the relay OFF
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(PUMP, HIGH); // set LED ON    test
        Blynk.virtualWrite(V42, 1);
        terminalPUMP.println("Everyday is ON");
        terminalPUMP.flush();
      
      }          
    }
  }
  else{
    terminalPUMP.println("Everyday INACTIVE today");
    terminalPUMP.flush();    
  }
  terminalPUMP.println();
}
}

 BLYNK_WRITE(V26) //Step Two
 {  
  if (steptwo==1) { 
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalLAMP.print("S-S Checked schedule at: ");
    terminalLAMP.println(Time);
    terminalLAMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
    dayadjustment =  6;
   }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){
    terminalLAMP.println("Step Two ACTIVE today");
    terminalLAMP.flush();
    if (t.hasStartTime())
    {
      terminalLAMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
    }
    if (t.hasStopTime())
    {
      terminalLAMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
    }
    terminalLAMP.println(String("Time zone: ") + t.getTZ()); 
    terminalLAMP.flush();
  
     for (int i = 1; i <= 7; i++) { 
        if (t.isWeekdaySelected(i)) {
        terminalLAMP.println(String("Day ") + i + " is selected");
        terminalLAMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalLAMP.print("Step Two STARTED at");
      terminalLAMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
      if(nowseconds <= startsecondswd + 90){ 
        digitalWrite(LAMP, HIGH);
        Blynk.virtualWrite(V22, 1);
      }      
    }
    else{
      terminalLAMP.println("Step Two NOT STARTED today");
      terminalLAMP.flush();
     
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    //Serial.println(stopsecondswd);
    if(nowseconds >= stopsecondswd){
      digitalWrite(LAMP, LOW);
      Blynk.virtualWrite(V22, 0);
      terminalLAMP.print("Step Two STOPPED at");
      terminalLAMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
      if(nowseconds <= stopsecondswd + 90){
        digitalWrite(LAMP, LOW);
        Blynk.virtualWrite(V22, 0);
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(LAMP, HIGH); // set LED ON  TEST
        Blynk.virtualWrite(V22, 1);
        terminalLAMP.println("Step Two is ON");
        terminalLAMP.flush();
      
      }          
    }
  }
  else{
    terminalLAMP.println("Step Two INACTIVE today");
    terminalLAMP.flush();  
  }
  terminalLAMP.println();
}
}

BLYNK_WRITE(V46) //fouweek PUMP
 {  
  if (fourweek==1) { 
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalPUMP.print("S-S Checked schedule at: ");
    terminalPUMP.println(Time);
    terminalPUMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
    dayadjustment =  6;
   }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){
    terminalPUMP.println("4 for week ACTIVE today");
    terminalPUMP.flush();
    if (t.hasStartTime())
    {
      terminalPUMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
    }
    if (t.hasStopTime())
    {
      terminalPUMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
    }
    terminalPUMP.println(String("Time zone: ") + t.getTZ()); 
    terminalPUMP.flush();
  
     for (int i = 1; i <= 7; i++) { 
        if (t.isWeekdaySelected(i)) {
        terminalPUMP.println(String("Day ") + i + " is selected");
        terminalPUMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalPUMP.print("4 for week STARTED at");
      terminalPUMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
      if(nowseconds <= startsecondswd + 90){ 
        digitalWrite(PUMP, HIGH);
        Blynk.virtualWrite(V42, 1);
      }      
    }
    else{
      terminalPUMP.println("4 for week NOT STARTED today");
      terminalPUMP.flush();
     
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    //Serial.println(stopsecondswd);
    if(nowseconds >= stopsecondswd){
      digitalWrite(PUMP, LOW);
      Blynk.virtualWrite(V42, 0);
      terminalPUMP.print("4 for week STOPPED at");
      terminalPUMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
      if(nowseconds <= stopsecondswd + 90){
        digitalWrite(PUMP, LOW);
        Blynk.virtualWrite(V42, 0);
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(PUMP, HIGH); // set LED ON  TEST
        Blynk.virtualWrite(V42, 1);
        terminalPUMP.println("4 for week is ON");
        terminalPUMP.flush();
      
      }          
    }
  }
  else{
    terminalPUMP.println("4 for week INACTIVE today");
    terminalPUMP.flush();  
  }
  terminalPUMP.println();
}
}

BLYNK_WRITE(V28)//Step Three
{  
  if (stepthree==1) {         
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalLAMP.print("Step Three Checked schedule at: ");
    terminalLAMP.println(Time);
    terminalLAMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
      dayadjustment =  6; 
    }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){
    terminalLAMP.println("Step Three ACTIVE today");
    terminalLAMP.flush();
    if (t.hasStartTime())
    {
      terminalLAMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
    }
    if (t.hasStopTime())
    {
      terminalLAMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
    }
    terminalLAMP.println(String("Time zone: ") + t.getTZ());
    terminalLAMP.flush();
  
     for (int i = 1; i <= 7; i++) {
        if (t.isWeekdaySelected(i)) {
        terminalLAMP.println(String("Day ") + i + " is selected");
        terminalLAMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalLAMP.print("Step Three STARTED at");
      terminalLAMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
      if(nowseconds <= startsecondswd + 90){
        digitalWrite(LAMP, HIGH); 
        Blynk.virtualWrite(V22, 1);
      }      
    }
    else{
      terminalLAMP.println("All Day Device NOT STARTED today");
      terminalLAMP.flush();
        
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    if(nowseconds >= stopsecondswd){
      digitalWrite(LAMP, LOW); // set LED OFF
      Blynk.virtualWrite(V22, 0);
      terminalLAMP.print("All day STOPPED at");
      terminalLAMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
      if(nowseconds <= stopsecondswd + 90){ 
        digitalWrite(LAMP, LOW);
        Blynk.virtualWrite(V22, 0);
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(LAMP, HIGH);
        Blynk.virtualWrite(V22, 1);
        terminalLAMP.println("All day is ON");
        terminalLAMP.flush();
      }          
    }
  }
  else{
    terminalLAMP.println("All day INACTIVE today");
    terminalLAMP.flush();
  }
  terminalLAMP.println();
}
}

BLYNK_WRITE(V48) //twoweek PUMP
{  
  if (twoweek==1) {         
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalPUMP.print("2 for week Checked schedule at: ");
    terminalPUMP.println(Time);
    terminalPUMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
      dayadjustment =  6; 
    }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){
    terminalPUMP.println("2 for week ACTIVE today");
    terminalPUMP.flush();
    if (t.hasStartTime())
    {
      terminalPUMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
    }
    if (t.hasStopTime())
    {
      terminalPUMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
    }
    terminalPUMP.println(String("Time zone: ") + t.getTZ());
    terminalPUMP.flush();
  
     for (int i = 1; i <= 7; i++) {
        if (t.isWeekdaySelected(i)) {
        terminalPUMP.println(String("Day ") + i + " is selected");
        terminalPUMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalPUMP.print("2 for week STARTED at");
      terminalPUMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
      if(nowseconds <= startsecondswd + 90){
        digitalWrite(PUMP, HIGH); 
        Blynk.virtualWrite(V42, 1);
      }      
    }
    else{
      terminalPUMP.println("2 for week Device NOT STARTED today");
      terminalPUMP.flush();
        
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    if(nowseconds >= stopsecondswd){
      digitalWrite(PUMP, LOW); // set LED OFF
      Blynk.virtualWrite(V42, 0);
      terminalPUMP.print("2 for week STOPPED at");
      terminalPUMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
      if(nowseconds <= stopsecondswd + 90){ 
        digitalWrite(PUMP, LOW);
        Blynk.virtualWrite(V42, 0);
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(PUMP, HIGH);
        Blynk.virtualWrite(V42, 1);
        terminalPUMP.println("2 for week is ON");
        terminalPUMP.flush();
      }          
    }
  }
  else{
    terminalPUMP.println("2 for week INACTIVE today");
    terminalPUMP.flush();
  }
  terminalPUMP.println();
}
}


BLYNK_WRITE(V30)//Up to you 
{  
  if (uptoyou==1) {         
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalLAMP.print("Up to you Checked schedule at: ");
    terminalLAMP.println(Time);
    terminalLAMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
      dayadjustment =  6;
    }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){
    terminalLAMP.println("Up to you ACTIVE today");
    terminalLAMP.flush();
    if (t.hasStartTime()) // Process start time
    {
      terminalLAMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
    }
    if (t.hasStopTime()) // Process stop time
    {
      terminalLAMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
    }
    terminalLAMP.println(String("Time zone: ") + t.getTZ()); 
    terminalLAMP.println("At least ONE day MUST be selected");
    terminalLAMP.flush();
  
     for (int i = 1; i <= 7; i++) {
        if (t.isWeekdaySelected(i)) {
        terminalLAMP.println(String("Day ") + i + " is selected");
        terminalLAMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalLAMP.print("Up to you STARTED at");
      terminalLAMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalLAMP.flush();
      if(nowseconds <= startsecondswd + 90){
        digitalWrite(LAMP, HIGH);
        Blynk.virtualWrite(V22, 1);
      }      
    }
    else{
      terminalLAMP.println("UP to you Device NOT STARTED today");
      terminalLAMP.flush();        
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    //Serial.println(stopsecondswd);  // used for debugging
    if(nowseconds >= stopsecondswd){
      digitalWrite(LAMP, LOW);
      Blynk.virtualWrite(V22, 0);
      terminalLAMP.print("Up to you STOPPED at");
      terminalLAMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalLAMP.flush();
      if(nowseconds <= stopsecondswd + 90){
        digitalWrite(LAMP, LOW);
        Blynk.virtualWrite(V22, 0);
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(LAMP, HIGH);
        Blynk.virtualWrite(V22, 1);
        terminalLAMP.println("Up to you is ON");
        terminalLAMP.flush();     
      }          
    }
  }
  else{
    terminalLAMP.println("Up to you INACTIVE today");
    terminalLAMP.flush(); 
  }
  terminalLAMP.println();
}
}

BLYNK_WRITE(V50) // oneweek PUMP
{  
  if (oneweek==1) {         
    sprintf(Date, "%02d/%02d/%04d",  day(), month(), year());
    sprintf(Time, "%02d:%02d:%02d", hour(), minute(), second());
  
    TimeInputParam t(param);
  
    terminalPUMP.print("1 for week Checked schedule at: ");
    terminalPUMP.println(Time);
    terminalPUMP.flush();
    int dayadjustment = -1;  
    if(weekday() == 1){
      dayadjustment =  6;
    }
    if(t.isWeekdaySelected(weekday() + dayadjustment)){
    terminalPUMP.println("1 for week ACTIVE today");
    terminalPUMP.flush();
    if (t.hasStartTime()) // Process start time
    {
      terminalPUMP.println(String("Start: ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
    }
    if (t.hasStopTime()) // Process stop time
    {
      terminalPUMP.println(String("Stop : ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
    }
    terminalPUMP.println(String("Time zone: ") + t.getTZ()); 
    terminalPUMP.println("At least ONE day MUST be selected");
    terminalPUMP.flush();
  
     for (int i = 1; i <= 7; i++) {
        if (t.isWeekdaySelected(i)) {
        terminalPUMP.println(String("Day ") + i + " is selected");
        terminalPUMP.flush();
        }
      } 
    nowseconds = ((hour() * 3600) + (minute() * 60) + second());
    startsecondswd = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
    //Serial.println(startsecondswd);  // used for debugging
    if(nowseconds >= startsecondswd){    
      terminalPUMP.print("1 for week STARTED at");
      terminalPUMP.println(String(" ") + t.getStartHour() + ":" + t.getStartMinute());
      terminalPUMP.flush();
      if(nowseconds <= startsecondswd + 90){
        digitalWrite(PUMP, HIGH);
        Blynk.virtualWrite(V42, 1);
      }      
    }
    else{
      terminalPUMP.println("1 for week Device NOT STARTED today");
      terminalPUMP.flush();        
    }
    stopsecondswd = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
    //Serial.println(stopsecondswd);  // used for debugging
    if(nowseconds >= stopsecondswd){
      digitalWrite(PUMP, LOW);
      Blynk.virtualWrite(V42, 0);
      terminalPUMP.print("1 for week STOPPED at");
      terminalPUMP.println(String(" ") + t.getStopHour() + ":" + t.getStopMinute());
      terminalPUMP.flush();
      if(nowseconds <= stopsecondswd + 90){
        digitalWrite(PUMP, LOW);
        Blynk.virtualWrite(V42, 0);
      }              
    }
    else{
      if(nowseconds >= startsecondswd){  
        digitalWrite(PUMP, HIGH);
        Blynk.virtualWrite(V42, 1);
        terminalPUMP.println("1 for week is ON");
        terminalPUMP.flush();     
      }          
    }
  }
  else{
    terminalPUMP.println("1 for week INACTIVE today");
    terminalPUMP.flush(); 
  }
  terminalPUMP.println();
}
}

void reconnectBlynk() {
  if (!Blynk.connected()) {
    if(Blynk.connect()) {
     BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

void sendData()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
//Write values to V08 and V09
  Blynk.virtualWrite(8, h);
  Blynk.virtualWrite(9, t);
}

void loop()
{
  if (Blynk.connected()) {
  long duration, distance;
  digitalWrite(TRIGGER, LOW);  
  delayMicroseconds(2); 
  
  digitalWrite(TRIGGER, HIGH);
  delayMicroseconds(10); 
  
  digitalWrite(TRIGGER, LOW);
  duration = pulseIn(ECHO, HIGH);
  distance = (duration/2) / 29.1;
  Blynk.virtualWrite(V15, distance);
  delay(200);
  Blynk.run();
  }
  timer.run();
}

#11

sorry but there are a lot of println, i had cut it in two.


#12

wow!! thanks, is really cool.


#13

hi guys, some news on the project. The project works, but i can use time input only between 10-23 :open_mouth: Doesn’t work from 0-9… i think is a problem of time format between rtc and time input.

Any idea about?

Thanks


#14

try 0:01 instead of 0:00
:wink:


#15

Hi Alexis, I’ve try also that but thi problem is in time format. I need to understand how to change format from 9.00 to 09.00… I don’t know how do that…


#16

I assume you want formatted clock display ?
this is :

void clockDisplay()
{
  String my_h = MyPrintDigits(hour());
  String my_m = MyPrintDigits(minute());
  String my_s = MyPrintDigits(second());

  currentTime = my_h+ my_m + my_s;
}
//fonction
String MyPrintDigits(int digits) { // -- Utility function for digital clock display: prints preceding colon and leading 0
  String new_digits = ":";
  if (digits < 10) new_digits += "0";
  new_digits += String(digits);
  return new_digits;
}

#17

… or try simply something like this:

void clockDisplay()
{
  ...
  sprintf(currentTime,"%02u:%02u:%02u",hour(),minute(),second()); 
  ...
}