I'm making a binary clock, and have some working code (for two digits only at present - run out of pins!) for a nano using a DS3231.
It works great.
But - I've noticed I don't have rtc.begin() in my code.
Is it really working? or is it not doing something I do need it to be doing??
I can unplug it and it comes back up with the correct time, and so far has had zero drift in 12hr, whereas the nanos internal clock drifts slow abut 45s/24hr. This tells me the RTC is functioning.
Code attached if needed, as I said, this is functioning well - it just displays the minutes as two binary digits.
I'm tossing up whether to use a mega pro mini and just keep direct wiring, or to use shift registers with the nano, I may do both for the education value in any case.
Thanks for any advice.....
#include <RTClib.h>
#include <Wire.h>
#include <Time.h>
#include <TimeLib.h>
DS3231 rtc;
int Bdigits[]={ 0,0,0,0,  //0
        0,0,0,1,  //1
        0,0,1,0,
        0,0,1,1,
        0,1,0,0,
        0,1,0,1,
        0,1,1,0,
        0,1,1,1,
        1,0,0,0,
        1,0,0,1};  //9
int secondsLeast;
int secondsMost;
int minutesLeast;Â Â Â Â // digit values
int minutesMost;
int hoursLeast;
int hoursMost;
int tick;Â Â Â Â Â Â Â Â // 1 sec heartbeat
int syncTick;
void setup() {
 Wire.begin();
 //Serial.begin(9600);
Â
 for (int p=2;p<10;p++) { pinMode(p,OUTPUT); }
 pinMode(13,OUTPUT);
Â
 //rtc.adjust(DateTime(2021, 3,3,22,32,50)); // yyyy,m,d,h,m,s
 tick=second();
Â
Â
}
void loop() {
DateTime now = rtc.now();Â Â Â // sync RTC
secondsLeast=now.second()%10;
secondsMost=now.second()/10;
minutesLeast=now.minute()%10;Â Â // calc digit values
minutesMost=now.minute()/10;
hoursLeast=now.hour()%10;
hoursMost=now.hour()/10;
 for (int t=0;t<4;t++){ digitalWrite(2+t,Bdigits[(minutesMost*4)+t]); } // LED display loops
   Â
 for (int t=0;t<4;t++){ digitalWrite(9-t,Bdigits[(minutesLeast*4)+t]); }
  Â
 if (now.second()!=tick) { digitalWrite(13,HIGH);
            delay(40);            // internal LED heartbeart
            digitalWrite(13,LOW);
            tick=now.second(); }
           Â
 //if (now.minute()!=syncTick) { DateTime now = rtc.now(); }        Â
 Â
}