problem with a keypad

hello
i am doing my first project in arduino and i am having a problem
the project is to make a traffic light and i need the user to enter the time he wants for each light
i made the code but it doesnot work well on proteus
it keeps returning to the yellow statement
i would appreciate any respond
i think i need a function that will clear the numbers i had pressed on the keypad

int pinled1 = 8;
int pinled2 = 9;
int pinled3 = 10;
int pinled4 = 18;
int pinled5 = 19;
char Redtime[4];
char Yellowtime[4];
char Greentime[4];

#include <Keypad.h>
const byte ROWS = 4; 
const byte COLS = 3;
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'},
};
byte rowPins[ROWS] = {17, 16, 15, 14}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Enter Redtime:");
  Redtime[0] = '0';
  Redtime[1] = '0';
  Redtime[2] = '0';
  Redtime[3] = '0';
  lcd.setCursor(0,1);
  lcd.print(Redtime[0]);
  lcd.print(Redtime[1]);
  lcd.print(Redtime[2]);
  lcd.print(Redtime[3]);
  pinMode (pinled1, OUTPUT );
  pinMode (pinled2, OUTPUT );
  pinMode (pinled3, OUTPUT );
  pinMode (pinled4, OUTPUT );
  pinMode (pinled5, OUTPUT );
  digitalWrite(pinled1, LOW);
  digitalWrite(pinled2, LOW);
  digitalWrite(pinled3, LOW);
  digitalWrite(pinled4, LOW);
  digitalWrite(pinled5, LOW);
}
  
void loop(){
  char key = keypad.getKey();
  lcd.setCursor(0,0);
  if (key != NO_KEY )
    {if (key != '#')
       {Redtime[0] = Redtime[1];
        Redtime[1] = Redtime[2];
        Redtime[2] = Redtime[3];
        Redtime[3] = key;
        lcd.setCursor(0,1);
        lcd.print(Redtime[0]);
        lcd.print(Redtime[1]);
        lcd.print(Redtime[2]);
        lcd.print(Redtime[3]);}
     else 
       {lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Enter Yellowtime");
        Yellowtime[0] = '0';
        Yellowtime[1] = '0';
        Yellowtime[2] = '0';
        Yellowtime[3] = '0';
        lcd.setCursor(0,1);
        lcd.print(Yellowtime[0]);
        lcd.print(Yellowtime[1]);
        lcd.print(Yellowtime[2]);
        lcd.print(Yellowtime[3]);
        if (key != NO_KEY )
           {if (key != '#')
              {Yellowtime[0] = Yellowtime[1];
               Yellowtime[1] = Yellowtime[2];
               Yellowtime[2] = Yellowtime[3];
               Yellowtime[3] = key;
               lcd.setCursor(0,1);
               lcd.print(Yellowtime[0]);
               lcd.print(Yellowtime[1]);
               lcd.print(Yellowtime[2]);
               lcd.print(Yellowtime[3]);}
            else 
              {lcd.clear();
               lcd.setCursor(0,0);
               lcd.print("Enter Greentime");
               Greentime[0] = '0';
               Greentime[1] = '0';
               Greentime[2] = '0';
               Greentime[3] = '0';
               lcd.setCursor(0,1);
               lcd.print(Greentime[0]);
               lcd.print(Greentime[1]);
               lcd.print(Greentime[2]);
               lcd.print(Greentime[3]);
               if (key != NO_KEY)
                 {if (key != '#')
                   {Greentime[0] = Greentime[1];
                    Greentime[1] = Greentime[2];
                    Greentime[2] = Greentime[3];
                    Greentime[3] = key;
                    lcd.setCursor(0,1);
                    lcd.print(Greentime[0]);
                    lcd.print(Greentime[1]);
                    lcd.print(Greentime[2]);
                    lcd.print(Greentime[3]);}
                  else 
                   {lcd.clear();
                    lcd.setCursor(0,0);
                    lcd.print("start");}}}}}}
        

  
              
             
        
        }

I always think this type of thing works better using a state machine.

Here's how I'd do it, it compiles but I don't have the hardware to test it, but you get the idea. (Uses your code up to the loop part)

enum states
{
  START = 0,
  ENTER_REDTIME,
  ENTER_YELLOWTIME,
  ENTER_GREENTIME,
  END,
};

states g_state = START;

void loop()
{
  char key = keypad.getKey();

  switch( g_state )
  {
    case START:
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Enter Greentime");
      g_state = ENTER_REDTIME;
    }
    case ENTER_REDTIME:
    {
      if (key != '#')
      {
        push_and_display_input( key, Redtime );
      }
      else
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Enter Yellowtime");
        memset( Yellowtime, 0, sizeof(Yellowtime));
        g_state = ENTER_YELLOWTIME;
      }
    }
    break;

    case ENTER_YELLOWTIME:
    {
      if (key != '#')
      {
        push_and_display_input( key, Yellowtime );
      }
      else
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Enter Greentime");
        memset( Greentime, 0, sizeof(Greentime));
        g_state = ENTER_GREENTIME;
      }
    }
    break;

    case ENTER_GREENTIME:
    {
      if (key != '#')
      {
        push_and_display_input( key, Greentime );
      }
      else
      {
        g_state = END;
      }
    }
    break;
    
    case END:
    {
      // Go back to the start ? ...
    }
    break;
  }
}

void push_and_display_input( char key, char *full_time_p )
{
  for( int i=0; i<3; i++ )
    full_time_p[i] = full_time_p[i+1];
  full_time_p[3] = key;
  lcd.setCursor(0,1);
  for( int i=0; i<4; i++ )
    lcd.print(full_time_p[i]);
}

thanks so much and it was really helpful
but i try it on proteus but it seems as it doesnot save the number entered
i also tried to make it print the number but it didnot work

void loop()
{
  char key = keypad.getKey();

  switch( g_state )
  {
    case START:
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Enter Redtime");
      g_state = ENTER_REDTIME;
    }
    case ENTER_REDTIME:
    {
      if (key != '#')
      {
        push_and_display_input( key, Redtime );
        lcd.setCursor(0,1);
        lcd.print(Redtime);
      }
      else
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Enter Yellowtime");
        memset( Yellowtime, 0, sizeof(Yellowtime));
        g_state = ENTER_YELLOWTIME;
      }
    }
    break;

    case ENTER_YELLOWTIME:
    {
      if (key != '#')
      {
        push_and_display_input( key, Yellowtime );
        lcd.setCursor(0,1);
        lcd.print(Yellowtime);
      }
      else
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Enter Greentime");
        memset( Greentime, 0, sizeof(Greentime));
        g_state = ENTER_GREENTIME;
      }
    }
    break;

    case ENTER_GREENTIME:
    {
      if (key != '#')
      {
        push_and_display_input( key, Greentime );
        lcd.setCursor(0,1);
        lcd.print(Greentime);
      }
      else
      {
        g_state = END;
      }
    }
    break;
    
    case END:
    { lcd.clear();
      lcd.setCursor(0,0);
      lcd.print(Redtime);
      lcd.setCursor(8,0);
      lcd.print(Yellowtime);
      lcd.setCursor(1,0);
      lcd.print(Greentime);
      // Go back to the start ? ...
    }
    break;
  }
}

void push_and_display_input( char key, char *full_time_p )
{
  for( int i=0; i<3; i++ )
    full_time_p[i] = full_time_p[i+1];
  full_time_p[3] = key;
  lcd.setCursor(0,1);
  for( int i=0; i<4; i++ )
    lcd.print(full_time_p[i]);
}
memset( Greentime, 0, sizeof(Greentime));

This fills the array with null characters. If you try to print the array you will get nothing unless all four characters are filled. Then, since you have no terminator, it will run off into other memory. To fill the array with ascii '0' characters:

memset( Greentime, '0', sizeof Greentime);

To add the required terminator, change the array size from 4 to 5 (to make room for the null) and set it explicitly:

memset( Greentime, '0', sizeof Greentime);
GreenTime[4] = 0;

Also, you could initialize at compile time:

char Redtime[] = "0000";
char Yellowtime[] = "0000";
char Greentime[] = "0000";

Then remove those memset() calls.

Greentime is memset, then in

void push_and_display_input( char key, char *full_time_p )

values are assigned to it, where individual characters should be printed. Not sure why its not working by looking at it.

thanks so much but it still doesnot print any number i press

Can you use the code I posted, and replace all the lcd.print() calls with Serial.println() and post the Serial output?

i am so sorry i donot have the hardware i just do it on proteus
i donot really know what is wrong too
but i was wondering if i can use the memset function with the keypad (with char key)
but it didnot work so is there is any function can do that as if i didnot press any key and just wait for a new key to be pressed
i know that i am bothering and i am also sorry about my bad english