#include <TM1637Display.h>
// Countdown Timer
unsigned long COUNTDOWN_TIME = 190; // 3:10 minutes in seconds
// Pins for TM1637 display module
#define CLK_PIN 2
#define DIO_PIN 3
TM1637Display display(CLK_PIN, DIO_PIN);
int addButton = 6;
unsigned long startTime;
unsigned long currentTime;
unsigned long elapsedTime;
//----------------------------------------------------------------------
void setup() {
display.setBrightness(7); // Set the brightness of the display (0-7)
display.clear(); // Clear the display
startTime = millis(); // Record the starting time
pinMode(addButton, INPUT_PULLUP);
}
//----------------------------------------------------------------------
void loop() {
if (digitalRead(addButton) == LOW)
{
delay(30);
if (digitalRead(addButton) == LOW)
{
COUNTDOWN_TIME = COUNTDOWN_TIME + 30;
while(digitalRead(addButton) == LOW){}
}
}
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);
}
}
}
}
/*#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);
void setup()
{
display.setBrightness(0x0f);
display.showNumberDec(1200);
}
void loop()
{
}*/