Keypad.Getkey() always returning noKey

Could someone go over the code and see what the problem is, it just skips over the get key and always returns no key

//ENTER PASSWORD ON KEYPAD
  void enterCode()
{

lcd.setCursor(0,0);
lcd.println("Enter password:");
lcd.setCursor(0 ,1);
lcd.print("                ");
enteredKey = keypad.getKey();

 if (enteredKey != NO_KEY) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
  {
    Data[data_count] = enteredKey; // store char into data array
    lcd.setCursor(data_count, 1); // move cursor to show each new char
    lcd.print(Data[data_count]); // print char at said cursor
    data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
  }
    
    else 
    {enterCode();}
    
    if (data_count == Password_Lenght - 1) // if the array index is equal to the number of expected chars, compare data to master
  {
    if (!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
    {
      lcd.clear();
     correctPassword();
    }
     
    }
}

You are calling the enterKey() function from inside the enterKey() function. Unless yoy really, really know what you are doing then such recursion is a very bad idea

Looks like you are trying to power your servo from the Arduino.

Servos need an external external power supply.

Make sure there is a common GND between the two Arduinos.

enterCode() is a function, enteredKey is a variable. There is no enteredKey function. I recall the enteredCode() in the else to bring it back to the start of the function so that when no key is pressed it try's again to get a key. So if I spam the key pad occasionally the number appears but it isn't sustainable.

When asking questions in the forums, please follow the forum’s posting guidelines.

Doing so gives volunteers all the information needed to effectively and quickly help you.

Now we are both wrong, so let's correct my mistake with the function name. You are calling the enterCode() function from inside the enterCode() function

1 Like

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