How can I fix this problem occur in code

When I upload code then first "PASSWARD...?" is showing on lcd diaplay,but when i press any key on keypad then only "lcd.clear()" is done and code ask to enter one more key to enter in following code.
How I remove this bug so, I can enter password just after the "PASSWARD...?" word.

#include <LiquidCrystal.h>
#include <Keypad.h>
/* Display */
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

/* Keypad setup */
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 4;
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};
byte colPins[KEYPAD_COLS] = {A3, A2, A1};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

Keypad customkeypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 1);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("PASSWARD...?");
}
void loop()
{
  while (1)
  {
    char customkey = customkeypad.getKey();
    if (customkey)
    {
      lcd.clear();
      break;
    }
  }

  while (1)
  {
    char customkey = customkeypad.getKey();
    if (customkey)
    {

      Serial.println(customkey);
      lcd.print(customkey);

      if (customkey == '#')
      {
        lcd.clear();
        break;
      }

    }
  }
}

Move the LCD clear command to setup().

What does this code do? Why did you put it there?

If I move their then my "password...?" word not print on lcd,
and delay is not solution for it...

this code get any key and
go into following code

Hi,
See if this code meets your needs.
I changed the keyboard setting to 3 because your keyboard is 4 rows x 3 columns.
const byte KEYPAD_COLS = 3;

#include <LiquidCrystal.h>
#include <Keypad.h>
/* Display */
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

/* Keypad setup */
const byte KEYPAD_ROWS = 4;
const byte KEYPAD_COLS = 3;
byte rowPins[KEYPAD_ROWS] = {5, 4, 3, 2};
byte colPins[KEYPAD_COLS] = {A3, A2, A1};
char keys[KEYPAD_ROWS][KEYPAD_COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
Keypad customkeypad = Keypad(makeKeymap(keys), rowPins, colPins, KEYPAD_ROWS, KEYPAD_COLS);
//-------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 1);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("PASSWARD...?");
}
//-------------------------------------------------------------
void loop()
{
  bool first = false;
  while (1)
  {
    char customkey = customkeypad.getKey();
    if (customkey)
    {
      if (first == false)
      {
        first = true;
        lcd.clear();
      }
      Serial.println(customkey);
      lcd.print(customkey);
      if (customkey == '#')
      {
        lcd.clear();
        break;
      }
    }
  }
}

Hi
???????

thank you sir✌️

Okay, why does it clear the screen?

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