countdown timer

hello

i looking for make a program (countdown timer)

i made a timer but i need it to be countdown timer (to enter a time (min and hour ) and count until arrive to set value.
help please.

#include <LiquidCrystal.h>
int s=0;
int m=0;
int h=0;
int d=0;

LiquidCrystal lcd(8,9,4,5,6,7);

void setup()
{
lcd.begin(16, 2);

}
void loop()
{
lcd.setCursor (8,0);
lcd.print (m);
lcd.print (" min ");

lcd.setCursor (0,0);
lcd.print (s);
lcd.print (" SEC ");

lcd.setCursor (0,1);
lcd.print (h);
lcd.print (" HOURS ");

lcd.setCursor (8,1);
lcd.print (d);
lcd.print (" DAY ");

if (s<60)
{
delay (1000);
s++;
}
if (s>59)
{
m++;
s=0;
delay(58);
}
if (m==60)
{
m=0;
h++;
delay(58);
}
if (h>23)
{
h=0;
d++;
delay(58);
}

}

The difference between counting down vs up is a matter of using -- instead of ++, and of delaing with the other boundary condition (what happens when you get to 0, vs what happens when you get to 60/24)?

    delay(58);What is the significance, if any, of 58 in these delay()s ?

A MCUH MUCH better way to handle a countdown is to dispense with hours and minutes and days and deal only in seconds. You can let the user enter the time in days, hours, minutes etc, but the program should immediately convert that to a value in seconds and only deal with counting down in seconds.

If you want to display the time in days, hours, minutes... then do that conversion when you do the display. But everything is much simpler if the part doing the counting doesn't have to deal with keeping up with 60 minutes and 24 hours and all that jazz.

Better countdown code to illustrate:

#define SEC_PER_MIN (60)
#define SEC_PER_HOUR (60ul * 60)
#define SEC_PER_DAY (24ul * 60 * 60)

unsigned long countdownTime = 0;

void setup(){  
  Serial.begin(9600);
  delay(20);
  Serial.println(F("Enter Days"));
  int days = getInputFromUser();
  Serial.println(F("Enter Hours"));
  int hours = getInputFromUser();
  Serial.println(F("Enter Minutes"));
  int minutes = getInputFromUser();
  Serial.println(F("Enter Seconds"));
  int seconds = getInputFromUser();
  
  countdownTime = seconds + (minutes * SEC_PER_MIN) + (hours * SEC_PER_HOUR) + (days * SEC_PER_DAY); 
}

void loop(){
  
  static unsigned long lastTick = millis();  
  unsigned long currentMillis = millis();
  
//  Way more accurate timing this way than with delay
//  Also allows for code to do other things during countdown
  if (currentMillis - lastTick >= 1000){
    lastTick += 1000;
    countdownTime--;
    displayTime(countdownTime);
  }
  
  if (countdownTime == 0){
    Serial.println(F("Countdown Finished"));
    while(1);  // infinite loop...  lock up program until reset
  }  
}

// blocks program for input from user via serial
// returns the number entered as an int
int getInputFromUser(){
  char buf[5];
  int index = 0;
  while(Serial.available() < 1);  // DO nothing until serial arrives
  
  buf[index] = Serial.read();
  
  while (buf[index] != '\n'){
    if(Serial.available()){
      buf[++index] = Serial.read();
    }
    //  Don't run over the end of buf
    if (index == 4){
      buf[index] = '\n';
      break;
    }
  }
  // Received a null, Serial transmission is over  
  return atoi(buf);
}


//Prints time to serial in D:H:M:S format  

void displayTime(unsigned long aTime){
  int seconds = aTime % SEC_PER_MIN;
  int minutes = (aTime % (SEC_PER_HOUR)) / SEC_PER_MIN;
  int hours = (aTime % (SEC_PER_DAY) / (SEC_PER_HOUR));
  int days = aTime / (SEC_PER_DAY);
  
  Serial.println(F("tick"));
  Serial.print(days);
  Serial.print(F(" : "));
  Serial.print(hours);
  Serial.print(F(" : "));
  Serial.print(minutes);
  Serial.print(F(" : "));
  Serial.println(seconds);
}

engyahia313:
i looking for make a program (countdown timer)

i made a timer but i need it to be countdown timer (to enter a time (min and hour ) and count until arrive to set value.
help please.

Is this a question about counting down time to zero?

Or is this a question about the LCD Keypad Shield (which you are using possibly) and how you can create an interactive menu using the shields buttons to enter data for the start values (day, hours, minutes, seconds), before then starting the countdown?