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. * 2 buttons for adjusting time.
*/ */
/* DS1307 lib by FrankieChu for Seeed RTC module, in my case /*
* Grove___RTC_DS1307-1.0.0.zip */ * uRTCLib
#include <DS1307.h> * 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> #include <SevSeg.h>
/* disable time compensation /* disable time compensation
@@ -21,7 +32,7 @@
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
DS1307 clock; uRTCLib clock;
SevSeg Display; SevSeg Display;
/* push button stuff */ /* push button stuff */
@@ -87,16 +98,14 @@ void setup()
Display.setBrightness(100); Display.setBrightness(100);
// setup clock // setup clock
clock.begin(); Wire.begin();
clock.set_rtc_address(0x68);
// if rtc returns incorrect time, reset it to some default value // if rtc returns incorrect time, reset it to some default value
clock.getTime(); clock.refresh();
if ((clock.hour > 23) || (clock.minute > 59)) { if ((clock.hour() > 23) || (clock.minute() > 59)) {
clock.fillByYMD(2019, 2, 23); // 23 Feb 2019 clock.set(30, 52, 15, 6, 23, 2, 19); // Saturday, 23 Feb 2019 15:52:30
clock.fillByHMS(15, 52, 30); // 15:52:30"
clock.fillDayOfWeek(SAT); // Saturday
clock.setTime(); // put date to rtc
} }
// setup control buttons // setup control buttons
@@ -175,24 +184,39 @@ void loop()
if (compflag1 && compflag2) { if (compflag1 && compflag2) {
#ifdef OFIVECOMP #ifdef OFIVECOMP
if (timeSkewEven) { 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 { } else {
#endif #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 #ifdef OFIVECOMP
} }
#endif #endif
clock.setTime();
compflag2 = false; compflag2 = false;
} }
#endif #endif
if (rtcsync) { if (rtcsync) {
clock.getTime(); clock.refresh();
mysecond = clock.second; mysecond = clock.second();
myminute = clock.minute; myminute = clock.minute();
myhour = clock.hour; myhour = clock.hour();
updateTimeStr(myhour, myminute); updateTimeStr(myhour, myminute);
rtcsync = false; rtcsync = false;
} }
@@ -221,15 +245,29 @@ void loop()
if (digitalRead(hrs_btn) == LOW) { if (digitalRead(hrs_btn) == LOW) {
myhour++; myhour++;
(myhour > 23) ? myhour = 0 : myhour; (myhour > 23) ? myhour = 0 : myhour;
clock.fillByHMS(myhour, myminute, 0); clock.set(
clock.setTime(); 0,
myminute,
myhour,
clock.dayOfWeek(),
clock.day(),
clock.month(),
clock.year()
);
} }
if (digitalRead(min_btn) == LOW) { if (digitalRead(min_btn) == LOW) {
myminute++; myminute++;
(myminute > 59) ? myminute = 0 : myminute; (myminute > 59) ? myminute = 0 : myminute;
clock.fillByHMS(myhour, myminute, 0); clock.set(
clock.setTime(); 0,
myminute,
myhour,
clock.dayOfWeek(),
clock.day(),
clock.month(),
clock.year()
);
} }
} }