0
我試圖在我的Arduino項目中使用RTC DS1307,每當我運行我的代碼時,我得到這個錯誤:RTC is not running
。該代碼應該每分鐘照亮一個LED:10sc並關閉每分鐘:20s。RTC沒有運行
這是我寫的代碼:
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
RTC_DS1307 rtc;
void setup()
{
Serial.begin(57600);
pinMode(0, OUTPUT);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
}
if (! rtc.isrunning()){
Serial.println("RTC is not running");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(0, 2);
Serial.println(now.month(),DEC);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(' ');
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
if (now.second() == 10)
{
digitalWrite (0, HIGH);
Serial.println("high");
}
else if (now.second() == 20)
{
digitalWrite (0, LOW);
Serial.println("low");
}
delay(1000);
}
我使用的Arduino網站RTClib.h庫。請任何想法。