Store input from keypad indepedently to control it in LCD

I need to design a circuit and write a program that does the following:

  1. initially displays on the LCD the time 00:00:00 (HOURS:MINUTES:SECONDS)
  2. uses the numerical keypad to change the current time
  • example: 15:25:35
  • maximum input: 59:59:59
  1. uses the * symbol to start/restart the countdown timer
  2. uses the # symbol to pause the countdown timer
  3. uses the A character to reset the countdown timer back to 00:00:00

I already finished the first, second and fifth tasks. But I currently having problem with controlling the display to count it down to zero.

Here’s my code:

#include <LiquidCrystal.h>
#include <Keypad.h>

LiquidCrystal lcd(7,6,5,4,3,2);

int x = 0;

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'#','0','*','D'}
};
byte rowPins[ROWS] = {A5,A4,A3,A2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A1,A0,12,13}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

void setup(){
  Serial.begin(9600); //for testing of keypad only
  lcd.begin(16,2);
  lcd.print("00:00:00");
}

void loop(){
  char key = keypad.getKey();
  Serial.print(key);
  delay(100);
  lcd.setCursor(x,0);
  
  if(isDigit(key)){
      lcd.print(key);
      delay(100);
      x++;
      if(x==2) x=3;
      if(x==5) x=6;
      if(x==8) x=0;
  }
  else if(key == '*'){
    //countdown play or pause
  }
  else if(key == '#'){
    //countdown timer reset
  }
  else if(key == 'A'){
    lcd.clear();
    lcd.print("00:00:00");
    int x = 0;
  }
  else if(key >= 6 && x == 0){
      int x = 0;
    }
    else if(key >= 6 && x == 3){
      int x = 3;
      x--;
    }
    else if(key >= 6 && x == 6){
      int x = 6;
      x--;
    }
}

In addition, I can’t limit the maximum to 59:59:59. When I pressed digits 6 to 9 in position (0,0) it still appears in the LCD. I want to limit the position (0,0), (3,0) and (6,0) from 0 to 5.

When I pressed digits 6 to 9 in position (0,0) it still appears in the LCD.

Because you are not doing anything to prevent that from happening.

      x++;
      if(x==2) x=3;
      if(x==5) x=6;
      if(x==8) x=0;

I gave some serious thought to using one letter words to comment on this. Then, I thought about 4 letter words, instead.

Use names that make sense. There is NOTHING in the name that suggests just what x is for.

  else if(key == 'A'){
    lcd.clear();
    lcd.print("00:00:00");
    int x = 0;
  }

Why are you creating another variable (x) with the same name as the other x? (That's why the 4 letter words came to mind).

What is the scope of that variable? Just exactly how useful is it?

int x = 0;

Int? Just how many digits can you display?