Search code examples
typesarduinokeypad

Arduino - What does NO_KEY mean and do?


I am trying to make a calculator project with an LCD and keypad but in order to do that I need to know what NO_KEY means.

void loop() {
  char customKey = keypad.getKey();
  
  if (customKey != NO_KEY)
  {
    Serial.println(customKey);
  }
}

Does anyone know what it could do?

Normally, without it the Serial monitor spits the right key but is flickering back and forth?

When I add this line in, it magically works.

Thanks for any help!


Solution

  • You are using the keypad.getKey() method. This means that every frame, you asking to see what the key pressed on the keypad is, even if a key isn't being pressed. If there is not a key being pressed, then it will give the value of NO_KEY.

    One way to integrate this is this:

    if (keypad.getKey() != NO_KEY)
    {
        // The code here will run whenever there is a key pressed
    }