Moderators: adafruit_support_bill, adafruit
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));The DS1307 is simple and inexpensive but not a high precision device. It may lose or gain up to 2 seconds a day. For a high-precision, temperature compensated alternative, please check out the ChronoDot.
The DS1307 is simple and inexpensive but not a high precision device. It may lose or gain up to 2 seconds a day. For a high-precision, temperature compensated alternative, please check out the ChronoDot.
poledust wrote:
I would have gone with the ChronoDot in the first place! The problem is not the second or two a month it is the fact that it does not keep 12hr time in the lib,
the time was 8:00 /20:00 but it showed 20:99 then when the minute was over it went to 20:01
So my question is do you know of code to get the 12hr
if (hour >= 12)
{
PM = true;
}
if (hour > 12) // afternoon hours
{
displayHour = hour - 12;
}
if (hour == 0) // special case for midnight
{
displayHour = 12;
}// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
RTC_DS1307 RTC;
void setup () {
Serial.begin(57600);
Wire.begin();
lcd.begin(20, 4);
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(__DATE__, __TIME__));
}
lcd.setCursor(0,0);
lcd.print("Starting up");
lcd.setCursor(0,1);
lcd.print("*** WELCOME! ***");
lcd.setCursor(0,3);
lcd.print("Initializing");
delay(4000);
lcd.clear();
}
void loop () {
DateTime now = RTC.now();
lcd.setCursor(0,0);
lcd.print(now.year(), DEC);
lcd.setCursor(4,0);
lcd.print("/");
lcd.setCursor(5,0);
lcd.print(now.month(), DEC);
lcd.setCursor(6,0);
lcd.print("/");
lcd.setCursor(7,0);
lcd.print(now.day(), DEC);
lcd.setCursor(12,0);
lcd.print(now.hour(), DEC);
lcd.setCursor(14,0);
lcd.print(":");
lcd.setCursor(15,0);
lcd.print(now.minute(), DEC);
lcd.setCursor(17,0);
lcd.print(":");
lcd.setCursor(18,0);
lcd.print(now.second(), DEC);
delay(1);
}Return to Arduino Shields from Adafruit
Users browsing this forum: No registered users and 5 guests