Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自blynk应用程序的Timewidget输入_Time_Arduino_Blynk - Fatal编程技术网

来自blynk应用程序的Timewidget输入

来自blynk应用程序的Timewidget输入,time,arduino,blynk,Time,Arduino,Blynk,我正在使用blynk应用程序开发基于时间的应用程序。若我的计时在设定的时限之间,则继电器必须打开,否则继电器必须关闭 我正在粘贴部分代码。在下面的代码中,如果我的时间设置在1小时范围内,它将工作。如果时间范围大于2小时,则无法工作。主要问题是比较时间小时和分钟 void TimeZone1_Function() { if (TimeZone1 == 1) { // call with timer every 30 seconds or so // Get RTC tim

我正在使用blynk应用程序开发基于时间的应用程序。若我的计时在设定的时限之间,则继电器必须打开,否则继电器必须关闭

我正在粘贴部分代码。在下面的代码中,如果我的时间设置在1小时范围内,它将工作。如果时间范围大于2小时,则无法工作。主要问题是比较时间小时和分钟

void TimeZone1_Function()
{

  if (TimeZone1 == 1)
  {
    // 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(stopTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
    Serial.print("Stop Time: ");
    Serial.println(stopTime);

    if (hour() >= SThour &&  hour() <= SPhour)
    {
      if (minute() >= STmin && minute() <= SPmin)
      {
        Serial.println("RELAY IS ON");
        Serial.println("..........................");
        digitalWrite(D5, HIGH); // Turn ON built-in LED
        led22.on();
      }
      else
      {
        Serial.println("RELAY IS OFF"); Serial.println("..........................");
        digitalWrite(D5, LOW); // Turn ON built-in LED
        led22.off();

      }
    }

    else
    {
      led22.off(); digitalWrite(D5, LOW);
        Blynk.virtualWrite(V51, 0);
    }

  }

}

如果你比较午夜后的秒数,事情会变得容易些。如果你知道你可以使用的日期,也就是从1970-01-01 00:00开始的秒数

int current_seconds = hour()*60*60 + minute()*60 + second();
int start_seconds = SThour*60*60 + STmin*60 + STsec;
int stop_seconds = SPhour*60*60 + SPmin*60 + SPsec;

// Is current time between set time limits?
if(current_seconds >= start_seconds && current_seconds <= stop_seconds)
{
  // Your relay code
}
int current_seconds=hour()*60*60+分钟()*60+秒();
int start_seconds=SThour*60*60+STmin*60+STsec;
int stop_秒=SPhour*60*60+SPmin*60+SPsec;
//当前时间是否在设定的时间限制之间?

如果(current_seconds>=start_seconds&¤t_seconds通过这种方式,我可以跟踪准确的时间。如果我比较时间,它为什么会失败,我的代码。如果我采用你的代码,它会做什么?我尝试使用DS1307,在那里我使用RTC时间。在这种情况下,它也会做同样的事情。谢谢让我尝试一下,将时间转换为总小时t out。感谢它开始工作。时间小部件应用程序允许您选择工作日。我想知道如何选择工作日。例如,我只想在周一、周三、周五操作时间。如何操作
int current_seconds = hour()*60*60 + minute()*60 + second();
int start_seconds = SThour*60*60 + STmin*60 + STsec;
int stop_seconds = SPhour*60*60 + SPmin*60 + SPsec;

// Is current time between set time limits?
if(current_seconds >= start_seconds && current_seconds <= stop_seconds)
{
  // Your relay code
}
// if requested on-time is overnight, e.g. 23:00 to 01:00
if (stop_seconds < start_seconds)
{
  stop_seconds += 24*60*60; // add a day
}