#include <TM1637Display.h>
unsigned long COUNTDOWN_TIME = 0;
#define CLK_PIN 2
#define DIO_PIN 3
#define ent 6
#define inc 5
#define dec 4
TM1637Display display(CLK_PIN, DIO_PIN);
unsigned long startTime;
void setup() {
pinMode(ent, INPUT);
pinMode(inc, INPUT);
display.setBrightness(7);
set_time();
}
void loop() {
timer();
set_time();
}
void set_time(){
display.showNumberDecEx(0, 0b01000000, true);
while (digitalRead(ent)==LOW){
if (digitalRead(inc)==HIGH){
delay(100);
COUNTDOWN_TIME+=1;
unsigned int minutes = COUNTDOWN_TIME/ 60;
unsigned int seconds = COUNTDOWN_TIME % 60;
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
}
if (digitalRead(dec)==HIGH){
delay(100);
COUNTDOWN_TIME-=1;
unsigned int minutes = COUNTDOWN_TIME/ 60;
unsigned int seconds = COUNTDOWN_TIME % 60;
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
}
}
}
void timer(){
startTime = millis();
unsigned long elapsedTime = (millis() - startTime) / 1000;
unsigned long remainingTime = COUNTDOWN_TIME - elapsedTime;
while (remainingTime != 0){
elapsedTime = (millis() - startTime) / 1000;
if (elapsedTime <= COUNTDOWN_TIME) {
remainingTime = COUNTDOWN_TIME - elapsedTime;
unsigned int minutes = remainingTime / 60;
unsigned int seconds = remainingTime % 60;
display.showNumberDecEx(minutes * 100 + seconds, 0b01000000, true);
}
}
}