'eKey' was not declared in this scope

I’m working on a 4x4 keypad password door lock and I keep getting the error message that ‘eKey’ was not declared. Can someone help me out please?

Keypad_door_lock.ino (1.3 KB)

In what scope have you declared eKey? None!

  keypad.getKey();

See if a key is being pressed. Throw away the answer. Why bother?

So how do I fix it?

So how do I fix it?

You have to declare that eKey is a variable of some type, some where.

You have to assign eKey a value somewhere.

Like:
(eKey=1)?

So I put : int eKey = 0; before void setup, and it compiled. Thanks so much bro

So I put : int eKey = 0; before void setup, and it compiled.

So, every time you press a key, you’ll use the value 0 in the switch statement and appending it to the password. Well, if that’s what you want.

I’m making a keypad servo lock and I have a problem, when I upload it, the serial monitor just prints
“DeniedEnter: 0” rapidly. I could really use some help heres my code

Keypad_door_lock.ino (1.3 KB)

Correction: this is my code

Keypad_door_lock.ino (1.32 KB)

I already answered this in your other thread.

I think you need to add a "NOT PRESSED" state so that it loops if no key is pressed.

Paul I have a new problem and how do I make it not do that

Your code is only 1400 bytes - well within the 9500 bytes allowed for a post. Copy and paste your code here, not as an attachment. Well, in the other thread, not here.

#include <Password.h>

#include <Servo.h>
#include <Keypad.h>
Servo servo;
Password password = Password(“5580”);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{’*’,‘0’,’#’,‘D’}
};
byte rowPins[ROWS] = {4,3,2,1}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8,7,6,5}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

int eKey = 0;
void setup() {
Serial.begin(9600);
delay(300);
keypad.addEventListener(keypadEvent);
servo.attach(13);

}

void loop() {
keypad.getKey();
servo.write(0);
switch (keypad.getState()){
case PRESSED:
Serial.print("Enter: ");
Serial.println(eKey);
delay(10);

Serial.write(254);

switch (eKey){
case ‘B’: checkPassword(); delay(1); break;
case ‘C’: password.reset(); delay(1); break;
default: password.append(eKey); delay(1);
}}
if (password.evaluate()){
Serial.println(“Lock 1 Opened”);
delay(10);
servo.write(50);
delay(15000);
servo.write(0);

}
else{
Serial.print(“Denied”);
servo.write(0);
}}
void checkPassword(){
}
void keypadEvent (KeypadEvent eKey){
}

int eKey = 0;

Set eKey to 0.

keypad.getKey();

See if a key is pressed. If so, do NOT save the key.

switch (keypad.getState()){
    case PRESSED:

See if a key is pressed. if so,

switch (eKey){
      case 'B': checkPassword(); delay(1); break;
      case 'C': password.reset(); delay(1); break;
      default: password.append(eKey); delay(1);
    }}

Well, eKey is not 'B' and it is not 'C', so append 0 to the password.

if (password.evaluate()){

Next, see if the password instance contains a correct password. All that you have entered is a bunch of NULLs, so, of course it doesn't. So,

else{
    Serial.print("Denied");

The question is why YOU expect anything else.

I'm just starting out, not very experienced I barely know anything so how would I know that

I barely know anything so how would I know that

Think about what is supposed to be in eKey at any time. It looks like it should be the last key read from the keypad, doesn't it?

   int eKey = keypad.getKey();

Get rid of the global variable named eKey.

I did int eKey = keypad.getkey(); and I got the error message: 'class Keypad' has no member named 'getkey'

C++ is case sensitive. getkey and getKey are two different things.

Arduino is based off of C not C++