/*
#include <TM1637Display.h>
// Define the connections pins
#define CLK 2 // Clock pin (CLK)
#define DIO 4 // Data pin (DIO)
// Initialize the display
TM1637Display display(CLK, DIO);
void setup() {
// Set the brightness (optional)
display.setBrightness(0x0f); // Maximum brightness
// Display the number "1234"
display.showNumberDec(1234);
}
void loop() {
// No action in the loop
}
*/
/* ................................................................. */
/*
#include <TM1637Display.h>
// Define the connections pins
#define CLK 2 // Clock pin (CLK)
#define DIO 4 // Data pin (DIO)
// Create an instance of the display
TM1637Display display(CLK, DIO);
// Variables to store the time (HH:MM)
int hours = 12; // Starting hours
int minutes = 0; // Starting minutes
unsigned long previousMillis = 0; // To store the last update time
void setup() {
// Set brightness (0 to 7 levels, 0x0f is max brightness)
display.setBrightness(0x0f);
}
void loop() {
// Get the current time in milliseconds
unsigned long currentMillis = millis();
// Update the time every 60 seconds
if (currentMillis - previousMillis >= 60000) {
previousMillis = currentMillis;
// Increment the minutes
minutes++;
// Roll over to the next hour if minutes reach 60
if (minutes >= 60) {
minutes = 0;
hours++;
}
// Roll over to 00:00 if hours reach 24
if (hours >= 24) {
hours = 0;
}
}
// Display the time in HH:MM format
int displayTime = (hours * 100) + minutes; // Combine hours and minutes
display.showNumberDecEx(displayTime, 0b01000000, true); // Display time with colon
}
*/
#include <TM1637Display.h>
// Define the connections pins
#define CLK 2 // Clock pin (CLK)
#define DIO 4 // Data pin (DIO)
// Create an instance of the display
TM1637Display display(CLK, DIO);
// Variables to store the time (MM:SS)
int minutes = 0; // Starting minutes
int seconds = 0; // Starting seconds
unsigned long previousMillis = 0; // To store the last update time
void setup() {
// Set the brightness of the display (0x0f is max brightness)
display.setBrightness(0x0f);
}
void loop() {
// Get the current time in milliseconds
unsigned long currentMillis = millis();
// Update the time every 1000 milliseconds (1 second)
if (currentMillis - previousMillis >= 1000) {
previousMillis = currentMillis;
// Increment the seconds
seconds++;
// Roll over to the next minute if seconds reach 60
if (seconds >= 60) {
seconds = 0;
minutes++;
}
// Roll over to 00:00 if minutes reach 60
if (minutes >= 60) {
minutes = 0;
}
}
// Display the time in MM:SS format
int displayTime = (minutes * 100) + seconds; // Combine minutes and seconds
display.showNumberDecEx(displayTime, 0b01000000, true); // Display time with colon
}