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

I need help with timeInput Widget


#1

Hi, I need help.
my code works perfectly during the day, but at the beginning of a new day the code gets lost.
for example:
I have a schedule with start 64800 ms or 18h
on the new day when nowSeconds is at 648ms the code executes as 64800ms

this problem occurs in
void lighting(){
and
void timerControl(){

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

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

BlynkTimer timer; // Object BlynkTimer (SimpleTimer)
WidgetRTC rtc;

char auth[] = "8cad"; // Token Blynk Server

#define W5100_CS  10
#define SDCARD_CS 4

// Define Define
const int porta01  = 24; // relay WaveMaker 1
const int porta02  = 25; // relay WaveMaker 2
const int porta03  = 26; // relay UV filter
const int porta04  = 27; // relay light on/off
const int controle = 28; // relay Control
const int alarme   = 29; // relay Alarm
const int led01    =  2; // led Day (white)
const int led02    =  3; // led Night (blue)

int rele01State = HIGH; // Start Relay 01
int rele02State = HIGH; // Start Relay 02
int rele03State = HIGH; // Start Relay 03
int rele04State = HIGH; // Start Relay 04
int rele05State = HIGH; // Start Relay 05
int rele06State = HIGH; // Start Relay 06

// Temperature Sensor
#define ONE_WIRE_BUS 22   // Define GPIO 22 to Temperature Sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float temp;

String nowSeconds;

void setup(){
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, IPAddress(10,12,25,100), 8080);
  //Blynk.begin(auth, "blynk.com.br", 6008);
  while (Blynk.connect() == false){ //Aguardando o Blynk Local Server se conectar
  }

  pinMode(porta01,  OUTPUT); // Declares pin 24 as output
  pinMode(porta02,  OUTPUT); // Declares pin 25 as output
  pinMode(porta03,  OUTPUT); // Declares pin 26 as output
  pinMode(porta04,  OUTPUT); // Declares pin 27 as output
  pinMode(controle, OUTPUT); // Declares pin 28 as output
  pinMode(alarme,   OUTPUT); // Declares pin 29 as output
  pinMode(led01,    OUTPUT); // Declares pin 2 as output
  pinMode(led02,    OUTPUT); // Declares pin 3 as output
  
  digitalWrite(controle, rele01State); //Receives initial status of Relay 01
  digitalWrite(alarme,   rele02State); //Receives initial status of Relay 02
  digitalWrite(porta01,  rele03State); //Receives initial status of Relay 03
  digitalWrite(porta02,  rele04State); //Receives initial status of Relay 04
  digitalWrite(porta03,  rele05State); //Receives initial status of Relay 05
  digitalWrite(porta04,  rele06State); //Receives initial status of Relay 06

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

  DS18B20.begin(); // Initializes the temperature sensor

  setSyncInterval(30 * 60); // Sets the time synchronization interval
  
  // Schedules
  timer.setInterval(2000L, clockDisplay); // Display digital clock every 5 seconds
  timer.setInterval(5000L, lighting); // Lighting timer 10 seconds
  timer.setInterval(5000L, timerControl); // WaveMaker Timer Control 10 seconds
  timer.setInterval(10000L, sendTemp); // Temperature Monitor 10 seconds
}

// Synchronize App ports
BLYNK_CONNECTED(){
  Serial.println("CONNECTED");
  Blynk.syncAll();
  rtc.begin(); // Start RTC Widget
}

void loop(){
  Blynk.run();
  timer.run();
}

//=======================================================================================
// Controle Leds

// Led Parameters
int pw0  =   0;
int pw1  =   5;
int pw2  =  10;
int pw3  =  25;
int pw4  =  50;
int pw5  =  75;
int pw6  = 100;
int pw7  = 125;
int pw8  = 150;
int pw9  = 175;
int pw10 = 200;
int pw11 = 225;

String sch0MLed;
String sch1MLed;
String sch2MLed;
String sch3MLed;
String sch4MLed;
String sch5MLed;
String sch6MLed;
String sch7MLed;
String sch8MLed;
String sch9MLed;
String sch10MLed;

String sch0NLed;
String sch1NLed;
String sch2NLed;
String sch3NLed;
String sch4NLed;
String sch5NLed;
String sch6NLed;
String sch7NLed;
String sch8NLed;
String sch9NLed;
String sch10NLed;

String startLedTimer;
String stopLedTimer;

String ledOff;

BLYNK_WRITE(V9){ // Function that changes the state of Relay 01 when the button in the APP is pressed
  rele06State = param.asInt(); // Variable receives and stores APP data
  digitalWrite(porta04, rele06State); // Change the status of Relay 01
}

int SThour;
int STmin;
int STsec;
int SPhour;
int SPmin;
int SPsec;

BLYNK_WRITE(V27) {
  TimeInputParam t(param);
  SThour = t.getStartHour();
  STmin = t.getStartMinute();
  STsec = t.getStartSecond();
  SPhour = t.getStopHour();
  SPmin = t.getStopMinute();
  SPsec = t.getStopSecond();
  
  if (t.hasStartTime()){
    startLedTimer = (t.getStartHour() * 3600L + t.getStartMinute() * 60);
    Serial.print("LED - Start Timer - ");
    Serial.println(startLedTimer);
  }
  else{
    // Do nothing
  }
  if (t.hasStopTime()){
    stopLedTimer = (t.getStopHour() * 3600L + t.getStopMinute() * 60);
    Serial.print("LED - Stop Timer - ");
    Serial.println(stopLedTimer);
  }
  else{
    // Do nothing: no stop time was set
  }
}

BLYNK_WRITE(V28){
  ledOff = param[0].asLong();
  Serial.println("ledOff");
  Serial.println(ledOff);
}

//=======================================================================================
// RTC

// Define RTC
const String DayOfWeek[7] = {"Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"};
const String Month[12] = {"Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"};
String showWeek;
String showMonth;
String currentTime;
String currentDate;

// Digital clock display of the time
String printDigits(int digits){
  String new_digits;
  if (digits < 10) {
    new_digits += "0";
  }
  new_digits += String(digits);
  return new_digits;
}

void clockDisplay(){
  showWeek = DayOfWeek[weekday()-1];
  showMonth = Month[month()-1];

  currentTime = String(printDigits(hour())) + ":" + printDigits(minute()) + ":" + printDigits(second());
  currentDate = String(showWeek) + " - " + printDigits(day()) + "/" + showMonth + "/" + year();
  
  /*
  Serial.print("Current time: ");
  Serial.print(showWeek);
  Serial.print(" ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();
  */
  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}

/*******************************************
 * Run the Leds Schedule
********************************************/
void lighting(){
//  String newDay = "00001";
//  String endDay = "86400L";

  nowSeconds = (hour() * 3600L + minute() * 60 + second());
  
  sch0MLed  = (SThour * 3600L + STmin * 60 + STsec);
  sch1MLed  = (SThour * 3600L + STmin * 60 + STsec + 300);
  sch2MLed  = (SThour * 3600L + STmin * 60 + STsec + 900);
  sch3MLed  = (SThour * 3600L + STmin * 60 + STsec + 1200);
  sch4MLed  = (SThour * 3600L + STmin * 60 + STsec + 1500);
  sch5MLed  = (SThour * 3600L + STmin * 60 + STsec + 1800);
  sch6MLed  = (SThour * 3600L + STmin * 60 + STsec + 2100);
  sch7MLed  = (SThour * 3600L + STmin * 60 + STsec + 2400);
  sch8MLed  = (SThour * 3600L + STmin * 60 + STsec + 2700);
  sch9MLed  = (SThour * 3600L + STmin * 60 + STsec + 3000);
  sch10MLed = (SThour * 3600L + STmin * 60 + STsec + 3300);

  sch0NLed  = (SPhour * 3600L + SPmin * 60 + SPsec);
  sch1NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 300);
  sch2NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 900);
  sch3NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 1200);
  sch4NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 1500);
  sch5NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 1800);
  sch6NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 2100);
  sch7NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 2400);
  sch8NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 2700);
  sch9NLed  = (SPhour * 3600L + SPmin * 60 + SPsec + 3000);
  sch10NLed = (SPhour * 3600L + SPmin * 60 + SPsec + 3300);

// Day Control
  if(nowSeconds >= startLedTimer && nowSeconds < ledOff){
    digitalWrite(porta04, LOW);
    if(rele06State == LOW){
      digitalWrite(porta04, LOW);
      if(nowSeconds >= startLedTimer && nowSeconds < stopLedTimer){
        if(nowSeconds >= sch0MLed && nowSeconds < sch1MLed){
          Serial.print("sch0MLed - ");
          Serial.println(sch0MLed);
          analogWrite(led01, pw2);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch1MLed && nowSeconds < sch2MLed){
          Serial.print("sch1MLed - ");
          Serial.println(sch1MLed);
          analogWrite(led01, pw3);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch2MLed && nowSeconds < sch3MLed){
          Serial.print("sch2MLed - ");
          Serial.println(sch2MLed);
          analogWrite(led01, pw4);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch3MLed && nowSeconds < sch4MLed){
          Serial.print("sch3MLed - ");
          Serial.println(sch3MLed);
          analogWrite(led01, pw5);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch4MLed && nowSeconds < sch5MLed){
          Serial.print("sch4MLed - ");
          Serial.println(sch4MLed);
          analogWrite(led01, pw6);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch5MLed && nowSeconds < sch6MLed){
          Serial.print("sch5MLed - ");
          Serial.println(sch5MLed);
          analogWrite(led01, pw7);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch6MLed && nowSeconds < sch7MLed){
          Serial.print("sch6MLed - ");
          Serial.println(sch6MLed);
          analogWrite(led01, pw8);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch7MLed && nowSeconds < sch8MLed){
          Serial.print("sch7MLed - ");
          Serial.println(sch7MLed);
          analogWrite(led01, pw9);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch8MLed && nowSeconds < sch9MLed){
          Serial.print("sch8MLed - ");
          Serial.println(sch8MLed);
          analogWrite(led01, pw10);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch9MLed && nowSeconds < sch10MLed){
          Serial.print("sch9MLed - ");
          Serial.println(sch9MLed);
          analogWrite(led01, pw10);
          analogWrite(led02, pw0);
        }
        else if(nowSeconds >= sch10MLed && nowSeconds < stopLedTimer){
          Serial.print("sch10MLed - ");
          Serial.println(sch10MLed);
          analogWrite(led01, pw10);
          analogWrite(led02, pw0);
        }
      }
    // Night Control
      else if(nowSeconds >= stopLedTimer && nowSeconds < ledOff){
        if(nowSeconds >= sch0NLed && nowSeconds < sch1NLed){
          Serial.print("sch0NLed - ");
          Serial.println(sch0NLed);
          analogWrite(led01, pw9);
          analogWrite(led02, pw2);
        }
        else if(nowSeconds >= sch1NLed && nowSeconds < sch2NLed){
          Serial.print("sch1NLed - ");
          Serial.println(sch1NLed);
          analogWrite(led01, pw8);
          analogWrite(led02, pw4);
        }
        else if(nowSeconds >= sch2NLed && nowSeconds < sch3NLed){
          Serial.print("sch2NLed - ");
          Serial.println(sch2NLed);
          analogWrite(led01, pw6);
          analogWrite(led02, pw6);
        }
        else if(nowSeconds >= sch3NLed && nowSeconds < sch4NLed){
          Serial.print("sch3NLed - ");
          Serial.println(sch3NLed);
          analogWrite(led01, pw4);
          analogWrite(led02, pw8);
        }
        else if(nowSeconds >= sch4NLed && nowSeconds < sch5NLed){
          Serial.print("sch4NLed - ");
          Serial.println(sch4NLed);
          analogWrite(led01, pw2);
          analogWrite(led02, pw10);
        }
        else if(nowSeconds >= sch5NLed && nowSeconds < sch6NLed){
          Serial.print("sch5NLed - ");
          Serial.println(sch5NLed);
          analogWrite(led01, pw1);
          analogWrite(led02, pw11);
        }
        else if(nowSeconds >= sch6NLed && nowSeconds < sch7NLed){
          Serial.print("sch6NLed - ");
          Serial.println(sch6NLed);
          analogWrite(led01, pw0);
          analogWrite(led02, pw8);
        }
        else if(nowSeconds >= sch7NLed && nowSeconds < sch8NLed){
          Serial.print("sch7NLed - ");
          Serial.println(sch7NLed);
          analogWrite(led01, pw0);
          analogWrite(led02, pw6);
        }
        else if(nowSeconds >= sch8NLed && nowSeconds < sch9NLed){
          Serial.print("sch8NLed - ");
          Serial.println(sch8NLed);
          analogWrite(led01, pw0);
          analogWrite(led02, pw4);
        }
        else if(nowSeconds >= sch9NLed && nowSeconds < sch10NLed){
          Serial.print("sch9MLed - ");
          Serial.println(sch9MLed);
          analogWrite(led01, pw0);
          analogWrite(led02, pw2);
        }
        else if(nowSeconds >= sch10NLed && nowSeconds < ledOff){
          Serial.print("sch10NLed - ");
          Serial.println(sch10NLed);
          analogWrite(led01, pw0);
          analogWrite(led02, pw1);
        }
      }
    }
    else if(rele06State == HIGH){
      Serial.println("ledOff...");
      digitalWrite(porta04, HIGH);
    }
  }
  else{
    Serial.println("Relay Led Off...");
    digitalWrite(porta04, HIGH);
  }
}

//=======================================================================================
// Controle Temperatura
int delta1Max = 0;
int delta2Max = 0;
int delta1Min = 0;
int delta2Min = 0;

BLYNK_WRITE(V12){ // Function Delta 1 Min
  delta1Min = param.asInt(); // Variable receives and stores APP data
}

BLYNK_WRITE(V13){ // Function Delta 2 Min
  delta2Min = param.asInt(); // Variable receives and stores APP data
}

BLYNK_WRITE(V14){ // Function Delta 1 Max
  delta1Max = param.asInt(); // Variable receives and stores APP data
}

BLYNK_WRITE(V15){ // Function Delta 2 Max
  delta2Max = param.asInt(); // Variable receives and stores APP data
}

// Instructions for sending Temperature data
void sendTemp(){
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0);

  Serial.print("Temperature: ");
  Serial.println(temp);
  
  Blynk.virtualWrite(V10,temp); // Virtual Port 10 graphic
  Blynk.virtualWrite(V11,temp); // Virtual Port 11 real time

  if(temp > delta2Min && temp < delta1Max){
    Blynk.virtualWrite(V6, 0); // Led Control
    Blynk.virtualWrite(V7, 0); // Led Alarm
    Serial.println("Control and Alarm Off");
    digitalWrite(controle, HIGH);
    digitalWrite(alarme,   HIGH);
  }
  else if(temp < delta1Min && temp <= delta2Min ){
    Blynk.virtualWrite(V6, 1023); // Led Control
    Blynk.virtualWrite(V7, 0); // Led Alarm
    Serial.println("Control On");
    digitalWrite(controle, LOW);
    digitalWrite(alarme,   HIGH);
  }
  else if(temp > delta1Max && temp >= delta2Max){
    Blynk.virtualWrite(V6, 0); // Led Control
    Blynk.virtualWrite(V7, 1023); // Led Alarm
    Serial.println("Alarm On");
    digitalWrite(controle, HIGH);
    digitalWrite(alarme,   LOW);
  }
  //else{
    //Blynk.virtualWrite(V6, 0); // Led Control
    //Blynk.virtualWrite(V7, 0); // Led Alarm
    //digitalWrite(controle, HIGH);
    //digitalWrite(alarme,   HIGH);
  //}
}

//=======================================================================================
// Timer Bombas

String startTimer1;
String stopTimer1;
String startTimer2;
String stopTimer2;
String startTimer3;
String stopTimer3;
String startTimer4;
String stopTimer4;
String startTimer5;
String stopTimer5;
String startTimer6;
String stopTimer6;

BLYNK_WRITE(V21){ // Schedule 1 WaveMaker 1
  TimeInputParam t(param);
  if (t.hasStartTime()){
    startTimer1 = (t.getStartHour() * 3600L + t.getStartMinute() * 60) + t.getStartSecond();
  }
  else{
    // Do nothing
  }
  if (t.hasStopTime()){
    stopTimer1 = (t.getStopHour() * 3600L + t.getStopMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing: no stop time was set
  }
}

BLYNK_WRITE(V22){ // Schedule 2 WaveMaker 1
  TimeInputParam t(param);
  if (t.hasStartTime()){
    startTimer2 = (t.getStartHour() * 3600L + t.getStartMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing
  }
  if (t.hasStopTime()){
    stopTimer2 = (t.getStopHour() * 3600L + t.getStopMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing: no stop time was set
  }
}

BLYNK_WRITE(V23){ // Schedule 1 WaveMaker 2
  TimeInputParam t(param);
  if (t.hasStartTime()){
    startTimer3 = (t.getStartHour() * 3600L + t.getStartMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing
  }
  if (t.hasStopTime()){
    stopTimer3 = (t.getStopHour() * 3600L + t.getStopMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing: no stop time was set
  }
}

BLYNK_WRITE(V24){ // Schedule 2 WaveMaker 2
  TimeInputParam t(param);
  if (t.hasStartTime()){
    startTimer4 = (t.getStartHour() * 3600L + t.getStartMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing
  }
  if (t.hasStopTime()){
    stopTimer4 = (t.getStopHour() * 3600L + t.getStopMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing: no stop time was set
  }
}

BLYNK_WRITE(V25){ // Schedule 1 UV Filter
  TimeInputParam t(param);
  if (t.hasStartTime()){
    startTimer5 = (t.getStartHour() * 3600L + t.getStartMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing
  }
  if (t.hasStopTime()){
    stopTimer5 = (t.getStopHour() * 3600L + t.getStopMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing: no stop time was set
  }
}

BLYNK_WRITE(V26){ // Schedule 2 UV Filter
  TimeInputParam t(param);
  if (t.hasStartTime()){
    startTimer6 = (t.getStartHour() * 3600L + t.getStartMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing
  }
  if (t.hasStopTime()){
    stopTimer6 = (t.getStopHour() * 3600L + t.getStopMinute() * 60 + t.getStartSecond());
  }
  else{
    // Do nothing: no stop time was set
  }
}

void timerControl(){
  nowSeconds = (hour() * 3600L + minute() * 60 + second());
  
  int sch1 = (nowSeconds >= "startTimer1" && nowSeconds < "stopTimer1");
  int sch2 = (nowSeconds >= startTimer2 && nowSeconds < stopTimer2);
  int sch3 = (nowSeconds >= startTimer3 && nowSeconds < stopTimer3);
  int sch4 = (nowSeconds >= startTimer4 && nowSeconds < stopTimer4);
  int sch5 = (nowSeconds >= startTimer5 && nowSeconds < stopTimer5);
  int sch6 = (nowSeconds >= startTimer6 && nowSeconds < stopTimer6);

  if(sch1 || sch2 || sch3 || sch4 || sch5 || sch6){
  Serial.println("Active Scheduling");
// Schedule 1 e 2 WaveMaker 1
    if(sch1){
      Serial.print("Schedule 1 - Started - ");
      Serial.print("Now Seconds");
      Serial.print(" - ");
      Serial.print(nowSeconds);
      Serial.print(" - ");
      Serial.print("Start Timer");
      Serial.print(" - ");
      Serial.println(startTimer1);
      
      Blynk.virtualWrite(V3, 1023);
      digitalWrite(porta01, LOW);
    }
  
    else if(sch2){
      Serial.print("Schedule 2 - Started - ");
      Serial.print("Now Seconds");
      Serial.print(" - ");
      Serial.print(nowSeconds);
      Serial.print(" - ");
      Serial.print("Start Timer");
      Serial.print(" - ");
      Serial.println(startTimer2);
      
      Blynk.virtualWrite(V3, 1023);
      digitalWrite(porta01, LOW);
    }
  
    else{
      Blynk.virtualWrite(V3, 0);
      digitalWrite(porta01, HIGH);
    }

// Schedule 3 e 4 WaveMaker 2
    if(sch3){
      Serial.print("Schedule 3 - Started - ");
      Serial.print("Now Seconds");
      Serial.print(" - ");
      Serial.print(nowSeconds);
      Serial.print(" - ");
      Serial.print("Start Timer");
      Serial.print(" - ");
      Serial.println(startTimer3);
      
      Blynk.virtualWrite(V4, 1023);
      digitalWrite(porta02, LOW);
    }
  
    else if(sch4){
      Serial.print("Schedule 4 - Started - ");
      Serial.print("Now Seconds");
      Serial.print(" - ");
      Serial.print(nowSeconds);
      Serial.print(" - ");
      Serial.print("Start Timer");
      Serial.print(" - ");
      Serial.println(startTimer4);
  
      Blynk.virtualWrite(V4, 1023);
      digitalWrite(porta02, LOW);
    }
  
    else{
      Blynk.virtualWrite(V4, 0);
      digitalWrite(porta02, HIGH);
    }

// Schedule 5 - 6 UV Filter
    if(sch5){
      Serial.print("Schedule 5 - Started - ");
      Serial.print("Now Seconds");
      Serial.print(" - ");
      Serial.print(nowSeconds);
      Serial.print(" - ");
      Serial.print("Start Timer");
      Serial.print(" - ");
      Serial.println(startTimer5);
  
      Blynk.virtualWrite(V5, 1023);
      digitalWrite(porta03, LOW);
    }
    else if(sch6){
      Serial.print("Schedule 6 - Started - ");
      Serial.print("Now Seconds");
      Serial.print(" - ");
      Serial.print(nowSeconds);
      Serial.print(" - ");
      Serial.print("Start Timer");
      Serial.print(" - ");
      Serial.println(startTimer6);
  
      Blynk.virtualWrite(V5, 1023);
      digitalWrite(porta03, LOW);
    }
    else{
      Blynk.virtualWrite(V5, 0);
      digitalWrite(porta03, HIGH);
    }
  }
  else{
    Serial.println("No Active Scheduling");
    digitalWrite(porta01, HIGH);
    digitalWrite(porta02, HIGH);
    digitalWrite(porta03, HIGH);
    Blynk.virtualWrite(V3, 0);
    Blynk.virtualWrite(V4, 0);
    Blynk.virtualWrite(V5, 0);
  }
}

sorry my poor english!


#2

you’d better use only one timer.
if you want more than one timer , you can try this way:

 timer.setInterval(1000L, timer_count); // Display digital clock every 5 seconds
int i=0;
void timer_count()
{
i++;
if(i==2)
clockDisplay();
else if(i==5)
lighting();
.....
}

just write on hand ,not test,so ,good luck.


#3

what you do ,looks like what i did before, an Internet Clock with LED
this is my project:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <Adafruit_NeoPixel.h>
#include <WidgetRTC.h>
#define RGB_PIN 12//RGB灯带连接管脚
#define MODULES 2// 2或者3分别表示HH:MM 或者 HH:MM:SS
#define RGB_NUM (MODULES * 47 + ( (MODULES - 1) * 5) )//LED灯珠总个数
Adafruit_NeoPixel strip = Adafruit_NeoPixel(RGB_NUM, RGB_PIN, NEO_GRB + NEO_KHZ800);
byte segGroups[14][3] = { //LED灯序号
  //从正面看右边的数字
  {6, 7, 8}, //顶部,a
  {9, 10, 11}, //右上,b
  {13, 14, 15}, //右下,c
  {16, 17, 18}, //底部,d
  {19, 20, 21}, //左下,e
  {3, 4, 5}, //左上,f
  {0, 1, 2}, //中间,g
  //从正面看左边的数字
  {38, 39, 40}, //顶部,a
  {41, 42, 43}, //右上,b
  {25, 26, 27}, //右下,c
  {28, 29, 30}, //底部,d
  {31, 32, 33}, //左下,e
  {35, 36, 37}, //左上,f
  {44, 45, 46} //中间,g
};
byte digits[12][7] = {
  {1, 1, 1, 1, 1, 1, 0}, //0
  {0, 1, 1, 0, 0, 0, 0}, //1
  {1, 1, 0, 1, 1, 0, 1}, //2
  {1, 1, 1, 1, 0, 0, 1}, //3
  {0, 1, 1, 0, 0, 1, 1}, //4
  {1, 0, 1, 1, 0, 1, 1}, //5
  {1, 0, 1, 1, 1, 1, 1}, //6
  {1, 1, 1, 0, 0, 0, 0}, //7
  {1, 1, 1, 1, 1, 1, 1}, //8
  {1, 1, 1, 1, 0, 1, 1}, //9
  {1, 0, 0, 1, 1, 1, 0}, //C
  {0, 1, 1, 0, 1, 1, 1} //H
};
byte current_sec;//当前秒数
char auth[] = "b46c053efc3d4db3819c7c387*******";//授权码
boolean dot = false;
int random_color = 20;
int rainbow;
int DisplayType = 0; //显示数据类型,0:时间;1:温度;2:湿度
int displayTempTime = 0; //标记显示温度或湿度的时间
BlynkTimer timer;
WidgetRTC rtc;//创建Blynk rtc组件

void showDots() {//显示冒号
  byte dot_leds[] = {47, 48, 50, 51, 99, 100, 102, 103 }; //冒号所在的LED灯序号
  byte show_leds = 0; //
  if (MODULES == 2)
    show_leds = 4;
  else if (MODULES == 3)
    show_leds = 8;
  if (dot) {//点亮冒号
    for (byte i = 0; i < show_leds; i++) {
      strip.setPixelColor(dot_leds[i], 360 - Wheel( random_color & 255));
      strip.show();
    }
  }
  else//熄灭冒号
  {
    for (byte i = 0; i < show_leds; i++) {
      strip.setPixelColor(dot_leds[i], strip.Color(0, 0, 0));
      strip.show();
    }
  }
  dot = !dot;
}


void clockDisplay()//显示时间
{
  byte ss_dec;//秒钟个位数
  byte ss_dig;//秒钟十位数
  byte mm_dec;//分钟个位数
  byte mm_dig;//分钟十位数
  byte hh_dec;//小时个位数
  byte hh_dig;//小时十位数
  ss_dec = second() * 0.1;
  if (current_sec != ss_dec)
  { //每隔10秒换颜色
    random_color = random(1, 180);
  }
  current_sec = ss_dec;
  ss_dig = second() - ss_dec * 10;
  mm_dec = minute() * 0.1;
  mm_dig = minute() - mm_dec * 10;
  hh_dec = hour() * 0.1;
  hh_dig = hour() - hh_dec * 10;
  //  showDigit(ss_dig, 0);
  //  showDigit(ss_dec, 1);
  showDigit(mm_dig, 0);
  showDigit(mm_dec, 1);
  showDigit(hh_dig, 2);
  showDigit(hh_dec, 3);
  showDots();
}

BLYNK_CONNECTED() {
  rtc.begin();//连上网络后同步时间
}

uint32_t Wheel(byte WheelPos) {//色轮
  if (WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

void showDigit(byte digit,  byte segDisplay) {//显示数字,digit为需要显示的数字,segDisplay为数字显示位置
  byte segOffset = 0; //默认数组坐标偏移量为0
  byte targetOffset = 0;//默认LED起点为0
  if (segDisplay == 0) {//第一位数字
    segOffset = 0;  //设置数组坐标偏移量
    targetOffset = 0;//设置LED起点
  }
  else if (segDisplay == 1) {//第二位数字
    segOffset = 7;
    targetOffset = 0;
  }
  else  if (segDisplay == 2) {//第三位数字
    segOffset = 0;
    targetOffset =  52;
  }
  else  if (segDisplay == 3) {//第四位数字
    segOffset = 7;
    targetOffset =  52;
  }
  else  if (segDisplay == 4) {//第五位数字
    segOffset = 0;
    targetOffset = 104;
  }
  else  if (segDisplay == 5) {//第六位数字
    segOffset = 7;
    targetOffset = 104;
  }
  for (byte i = 0; i < 7; i++) {
    if (digits[digit][i] != 0) {//点亮LED
      for (byte j = 0; j < 3; j++) {
        strip.setPixelColor(segGroups[i + segOffset][j] + targetOffset , Wheel( random_color & 255));
      }
      strip.show();
    }
    else//关闭LED
      for (byte j = 0; j < 3; j++) {
        strip.setPixelColor(segGroups[i + segOffset][j] + targetOffset , strip.Color(0, 0, 0));
      }
      strip.show();
    }
  }

void bootRainBow()//开机彩虹效果
{
 strip.begin();
 strip.setBrightness(100);
 rainbow = random(1, 180);
 for (int i = 0; i < strip.numPixels(); i++)
  { //开机亮彩虹
    strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + rainbow) & 255));
    strip.show();
    delay(20);
  }
  for (int i = strip.numPixels(); i >= 0; i--)
  { //开机灭彩虹
    strip.setPixelColor(i, 0, 0, 0);
    strip.show();
    delay(20);
  }
}

void setup()
{
  bootRainBow();//开机彩虹效果
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  int cnt = 0;
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
    if (cnt++ >= 10) 
    {
      WiFi.beginSmartConfig();
      while (1) 
      {
        delay(1000);
        if (WiFi.smartConfigDone()) 
        {
          Serial.println();
          Serial.println("SmartConfig: Success");
          break;
        }
        Serial.print("|");
      }
    }
  }  
  WiFi.printDiag(Serial);
  Blynk.config(auth,IPAddress(192, 168, 2, 166),8080);
  setSyncInterval(10 * 60); // 设置同步间隔时间10分钟。
  timer.setInterval(1000L, clockDisplay);//每隔1s,运行Display,显示内容
}

void loop()
{
  Blynk.run();
  timer.run();
}