#include <TM1637Display.h>
// Countdown Timer
const unsigned long COUNTDOWN_TIME = 45; // 5 minutes in seconds
// Pins for TM1637 display module
#define CLK_PIN 2
#define DIO_PIN 3
#define start_pin 13;
static boolean pause = 1;
unsigned long speeder = 1000;
int seconds = 0;
int minutes = 0;
static int counter = 0;
unsigned long startTime;
unsigned long currentTime;
unsigned long elapsedTime;
bool timerStarted = false;
TM1637Display display(CLK_PIN, DIO_PIN);
void reset_countdown()
{
print_serial("Countdown reset\n");
seconds = 0;
minutes = 0;
pause = true;
speeder = 1000;
last_alarm = -1;
}
void setup() {
Serial.begin(9600);
pinMode(start_pin, INPUT_PULLUP);
display.setBrightness(7); // Set the brightness of the display (0-7)
display.clear(); // Clear the display
reset_countdown();
Serial.println("Ready\n");
startTime = millis(); // Record the starting time
}
void loop() {
if (digitalRead(BTN_START) == LOW) {
timerStarted=1;
}
currentTime = millis(); // Get the current time
elapsedTime = (currentTime - startTime) / 1000; // Calculate elapsed time in seconds
if (elapsedTime <= COUNTDOWN_TIME) {
unsigned long remainingTime = COUNTDOWN_TIME - elapsedTime;
// Display remaining time in Minutes:Seconds format
unsigned int minutes = remainingTime / 60;
unsigned int seconds = remainingTime % 60;
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
if (remainingTime == 0) {
// Start blinking when countdown reaches 00:00
while (true) {
display.showNumberDecEx(0, 0b01000000, true); // Display "00:00"
delay(500);
display.clear(); // Clear the display
delay(500);
}
}
}
delay(100); // Wait for 1 second
}