我是一个新手,正在尝试设置一个简单的过程来像大本钟一样根据分秒来操作 2 个伺服系统和 LED。我可以使用这段代码非常简单地连接到我的 wifi 并在串行屏幕上打印分钟和秒;
//从互联网获取ESP8266时间
#include "NTPClient.h"
#include "ESP8266WiFi.h"
#include "WiFiUdp.h"
const char *ssid = "my wifi name";
const char *password = "我的wifi密码";
const long utcOffse
tinSeconds = -18000;
//char daysOfTheWeek[7][12] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
void setup(){
Serial.begin(115200);
WiFi.begin(ssid, 密码);
while ( WiFi.status() != WL_CONNECTED ) {
延迟 ( 500 );
Serial.print(".");
}
timeClient.begin();
}
void loop() {
timeClient.update();
//Serial.print(daysOfTheWeek[timeClient.getDay()]);
序列号.print(",");
//Serial.print(timeClient.getHours());
序列号.print(":");
Serial.print(timeClient.getMinutes());
序列号.print(":");
Serial.println(timeClient.getSeconds());
//Serial.println(timeClient.getFormattedTime());
延迟(1000);
}
现在让我感到困惑的部分是,我发现每个使用 wifi 时间运行草图功能的项目都使用从微秒开始的非常复杂和冗长的过程。
有没有简单的方法,直接从wifi读取分秒,在0分-0秒、15分-0秒、30分-0秒、45分-0秒触发草图功能,然后从0开始-分钟,0秒?
分秒组合在串行屏幕中每小时出现一次,为什么我不能只选择这个时间组合并让它触发一个动作?我的应用程序不需要毫秒精度。
我确定我过度简化了这一点,但有人可以帮助我理解。
谢谢