1

Migrate Grove RTC DS1307 -> uRTCLib

This commit is contained in:
eleksir
2019-10-20 00:05:50 +03:00
parent acc53eaa74
commit 0c91c05486

View File

@@ -6,9 +6,20 @@
* 2 buttons for adjusting time.
*/
/* DS1307 lib by FrankieChu for Seeed RTC module, in my case
* Grove___RTC_DS1307-1.0.0.zip */
#include <DS1307.h>
/*
* uRTCLib
* https://github.com/Naguissa/uRTCLib
* it has support for both DS1307 and DS3231, that i own.
* It is more fat than ds1307-dedicated or ds3231-dedicated lib, but i do not
* want to invent wheel if i have one.
*/
#include <uRTCLib.h>
/*
* SevSeg
* https://github.com/DeanIsMe/SevSeg
* it has simple api and ideally works in my case
*/
#include <SevSeg.h>
/* disable time compensation
@@ -21,7 +32,7 @@
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
DS1307 clock;
uRTCLib clock;
SevSeg Display;
/* push button stuff */
@@ -87,16 +98,14 @@ void setup()
Display.setBrightness(100);
// setup clock
clock.begin();
Wire.begin();
clock.set_rtc_address(0x68);
// if rtc returns incorrect time, reset it to some default value
clock.getTime();
clock.refresh();
if ((clock.hour > 23) || (clock.minute > 59)) {
clock.fillByYMD(2019, 2, 23); // 23 Feb 2019
clock.fillByHMS(15, 52, 30); // 15:52:30"
clock.fillDayOfWeek(SAT); // Saturday
clock.setTime(); // put date to rtc
if ((clock.hour() > 23) || (clock.minute() > 59)) {
clock.set(30, 52, 15, 6, 23, 2, 19); // Saturday, 23 Feb 2019 15:52:30
}
// setup control buttons
@@ -175,24 +184,39 @@ void loop()
if (compflag1 && compflag2) {
#ifdef OFIVECOMP
if (timeSkewEven) {
clock.fillByHMS(myhour, myminute, (mysecond - timeSkew - 1));
clock.set(
(mysecond - timeSkew - 1),
clock.minute(),
clock.hour(),
clock.dayOfWeek(),
clock.day(),
clock.month(),
clock.year()
);
} else {
#endif
clock.fillByHMS(myhour, myminute, (mysecond - timeSkew));
clock.set(
(mysecond - timeSkew),
clock.minute(),
clock.hour(),
clock.dayOfWeek(),
clock.day(),
clock.month(),
clock.year()
);
#ifdef OFIVECOMP
}
#endif
clock.setTime();
compflag2 = false;
}
#endif
if (rtcsync) {
clock.getTime();
mysecond = clock.second;
myminute = clock.minute;
myhour = clock.hour;
clock.refresh();
mysecond = clock.second();
myminute = clock.minute();
myhour = clock.hour();
updateTimeStr(myhour, myminute);
rtcsync = false;
}
@@ -221,15 +245,29 @@ void loop()
if (digitalRead(hrs_btn) == LOW) {
myhour++;
(myhour > 23) ? myhour = 0 : myhour;
clock.fillByHMS(myhour, myminute, 0);
clock.setTime();
clock.set(
0,
myminute,
myhour,
clock.dayOfWeek(),
clock.day(),
clock.month(),
clock.year()
);
}
if (digitalRead(min_btn) == LOW) {
myminute++;
(myminute > 59) ? myminute = 0 : myminute;
clock.fillByHMS(myhour, myminute, 0);
clock.setTime();
clock.set(
0,
myminute,
myhour,
clock.dayOfWeek(),
clock.day(),
clock.month(),
clock.year()
);
}
}