#include "RTClib.h"
#include <TM1637Display.h>
// Define the connections pins for TM1637 4 digit 7 segment display
#define CLK 8
#define DIO 9
// Define the connections pin for DS3231 RTC Module
// SCL - A5
// SDA - A4
// VCC - VCC
// GNG - GND
// Create rtc and display object
RTC_DS3231 rtc;
TM1637Display display = TM1637Display(CLK, DIO);
void setup() {
// Begin serial communication at a baud rate of 9600
Serial.begin(9600);
// Wait for console opening
delay(3000);
// 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.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
// Set the RTC with an explicit date & time
rtc.adjust(DateTime(2024, 6, 12, 12, 0, 0)); // Set to June 12, 2024, 12:00:00
}
// Set the display brightness (0-7):
display.setBrightness(5);
// Clear the display:
display.clear();
}
void loop() {
// Get current date and time
DateTime now = rtc.now();
// Create time format to display:
int displaytime = (now.hour() * 100) + now.minute();
// Print displaytime to the Serial Monitor
Serial.println(displaytime);
// Display the current time in 24 hour format with leading zeros enabled and a center colon:
display.showNumberDecEx(displaytime, 0b11100000, true);
// Remove the following lines of code if you want a static instead of a blinking center colon:
delay(1000);
display.showNumberDec(displaytime, true); // Prints displaytime without center colon.
delay(1000);
}