第一次玩ds3231,想做时控灯,为什么不定时开灯呢
#include <DS3231.h>// Init the DS3231 using the hardware interface
DS3231rtc(SDA, SCL);
void setup()
{
// Setup Serial connection
Serial.begin(115200);
// Uncomment the next line if you are using an Arduino Leonardo
//while (!Serial) {}
// Initialize the rtc object
rtc.begin();
// The following lines can be uncommented to set the date and time
// rtc.setDOW(SATURDAY); // Set Day-of-Week to SUNDAY
rtc.setTime(17,8,00); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(30,5,2020); // Set the date to January 1st, 2014
}
void loop()
{
int aa=13;
if (rtc.getTimeStr()=="17:10:00")
{
digitalWrite(13,HIGH);
delay(100);
}
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}
大神们,帮我看看看吧
你应该看看你的时间走到哪里了!应该弄个串口打印之类的,看你的程序如果中间重新上电,时间会从0点重新走时。时间设定不能每次上电都无条件执行。最好弄个串口设定时间。
页:
[1]