Hello!
For a long time I want to make a common digital clock with Arduino-DS3231 RTC-TM1637. Personally, I did not find on the internet a program that runs in real time, I saw that the clock resets back to the moment when the program was compiled if the power drops. It's frustrating, I invested some money in a second RTC DS3231 module with a battery and a display, and in vain, the circuit still does not work properly.
The problem is that this program works halfway, the time is delayed by about 15 minutes compared to the actual real time, I really don't know how and why. It is frustrating.
#include "TM1637.h"
#define CLK 9//Pins for TM1637
#define DIO 8
TM1637 tm1637(CLK,DIO);
#include <Wire.h>
#include "RTClib.h"
// SDA->A4 SCL->A5
RTC_DS1307 RTC;
int hh, mm;
void setup()
{
tm1637.init();
tm1637.set(5);
//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
Wire.begin();
RTC.begin();
// Check if RTC is connected correctly:
/if (! RTC.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}/
// Check if the RTC lost power and if so, set the time:
/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));
RTC.adjust(DateTime(2021, 5, 8, 3, 0, 0));
}/
}//end "setup()"
void loop(){
DateTime now = RTC.now();
hh = now.hour(), DEC;
mm = now.minute(), DEC;
tm1637.point(POINT_ON);
if ((hh/10) == 0) tm1637.display(0,17);
else
tm1637.display(0,hh/10); // hour
tm1637.display(1,hh%10);
tm1637.display(2,mm/10); // minutes
tm1637.display(3,mm%10);
delay(500);
tm1637.point(POINT_OFF);
if ((hh/10) == 0) tm1637.display(0,17);
else
tm1637.display(0,hh/10); // hour
tm1637.display(1,hh%10);
tm1637.display(2,mm/10); // minutes
tm1637.display(3,mm%10);
delay(500);
}// end loop()