极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 22762|回复: 3

第一次玩ds3231,想做时控灯,为什么不定时开灯呢

[复制链接]
发表于 2020-5-31 14:57:20 | 显示全部楼层 |阅读模式
#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231  rtc(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);


}
回复

使用道具 举报

 楼主| 发表于 2020-5-31 14:57:56 | 显示全部楼层
大神们,帮我看看看吧
回复 支持 反对

使用道具 举报

发表于 2020-6-9 09:45:06 | 显示全部楼层
你应该看看你的时间走到哪里了!应该弄个串口打印之类的,看你的程序如果中间重新上电,时间会从0点重新走时。时间设定不能每次上电都无条件执行。最好弄个串口设定时间。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-24 21:12 , Processed in 0.039370 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表