#include <TM1637.h>
const int CLK = 2;
const int DIO = 4;
unsigned long previousMillis = 0;
const long interval = 1000; // Interval between countdown updates in milliseconds (1 second)
int minutes = 70; // Initial minutes value
int seconds = 0;
TM1637 tm(CLK, DIO);
void setup() {
tm.init();
tm.set(BRIGHT_TYPICAL);
}
void updateCountdown() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (seconds > 0) {
seconds--; // Decrement seconds
} else {
if (minutes > 0) {
minutes--; // Decrement minutes if seconds reach 0
seconds = 59; // Reset seconds to 59
} else {
// Countdown finished, you can reset it or stop the countdown
minutes = 0;
seconds = 0;
}
}
// Display minutes and seconds on the TM1637
tm.display(0, (minutes / 10) % 10); // Tens place of minutes
tm.display(1, minutes % 10); // Ones place of minutes
tm.display(2, (seconds / 10) % 10); // Tens place of seconds
tm.display(3, seconds % 10); // Ones place of seconds
tm.point(true);
}
}
void loop() {
updateCountdown();
}