Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15454

Adding 30sec to a count down timer using Tm1637

$
0
0

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
}

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15454

Trending Articles