Adding 30sec to a count down timer using Tm1637

Hi I'm trying to create a timer that starts on it's own when powered on but want to add 30 seconds when ever I push a button any help is greatly appreciate it.

#include <TM1637Display.h>


// Countdown Timer
const unsigned long COUNTDOWN_TIME = 190; // 3:10 minutes in seconds


// Pins for TM1637 display module
#define CLK_PIN 2
#define DIO_PIN 3

int addButton=6;


TM1637Display display(CLK_PIN, DIO_PIN);


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
  
  for (int i=0; i<4; i++){
       pinMode(digital_pin[i], OUTPUT);
  }
  pinMode(addButton,INPUT_PULLUP);
}


void loop() {
  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(1000); // Wait for 1 second
}

That delay is much, much too long.
Remember, during a delay(), your Arduino is essentially frozen, and cannot respond to events such as button presses. A delay of 10 or maybe 20 milliseconds, for purposes of debouncing a switch, is OK. A delay of 1000 milliseconds is not OK.

I see you are trying to use a button, which is a kind of switch. You can learn more about switches (including what debouncing is and why you need to do it) here:
https://www.ladyada.net/learn/arduino/lesson5.html

add to what? to constant COUNTDOWN_TIME or to elapsedTime ?

Try this code:

Thank you so much, what software is that you send me that's awsome?

I did not understand your question.
Can you please explain better?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.