How to use NO_KEY ?

Generally it's a bad idea to put your sketch in a loop waiting for a key press. Humans are very slow and your sketch can be doing useful stuff other than waiting for a human. You also don't need to check for NO_KEY before you decise what to do with the key value. Just pass every value on to the switch/case statement. If you want something special done when no key was pressed, you can make a 'case NO_KEY:'.

void setup () {
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.print ("HELLLO");  // Dispay "HELLO" until the '1' key is pressed.
}

void loop() 
{
  customkey = customKeypad.getKey();

  switch(customkey) {
  case '1':
    lcd.clear();
    lcd.setCursor(9,0);
    lcd.print("WELCOME");
    break;
  }
}
1 Like