#include <TM1637Display.h>
// Define the connections to the display
#define CLK 22 // Clock pin (D22)
#define DIO 21 // Data pin (D21)
// Create an instance of the TM1637 display
TM1637Display display(CLK, DIO);
// Variables for time
int hours = 0;
int seconds = 0;
unsigned long previousMillis = 0; // To track time
void setup() {
// Set the brightness of the display (0-7)
display.setBrightness(7);
}
void loop() {
// Get the current time in milliseconds
unsigned long currentMillis = millis();
// Update time every second
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
seconds++;
// Increment the hour when seconds reach 60
if (seconds >= 60) {
seconds = 0;
hours++;
}
// Reset hours if it reaches 24 (like a clock)
if (hours >= 24) {
hours = 0;
}
// Display the time in HH:SS format
displayTime(hours, seconds);
}
}
// Function to display time in HH:SS format
void displayTime(int hours, int seconds) {
int displayValue = (hours * 100) + (seconds); // Combine hours and seconds into one number
// Show time with a colon between hours and seconds
display.showNumberDecEx(displayValue, 0b01000000, true);
}