Hi I'm studying some keypad functions and I encounter this handy condition but I don't know how it works.
I did a simple test in where word will display if you use NO_KEY and then the lcd will clear and display new set of string.
Here's my code
#include <Keypad.h>
#include <Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char customkey;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 10, 11, 12}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup (){
Serial.begin(9600);
lcd.begin(16,2);
}
void loop()
{
customkey = customKeypad.getKey();
while(customkey == NO_KEY )
{ customkey = customKeypad.getKey();
lcd.print ("HELLLO");}
if (customkey != NO_KEY)
{
switch(customkey)
{
case '1':
lcd.clear();
lcd.setCursor(9,0);
lcd.print("WELCOME");
break;
}
}
}
My main problem is the word HELLO keeps on displaying even if the condition about NO_KEY is terminated after pressing a KEY
Any help is appreciated,
THANK YOU!