This is my second Sketch on my Arduino UNO. First was for a fingerprint reader, and works perfect. I thought the keypad would be easier, but I can not get a sketch to load. I need to have this up and running tomorrow. If someone out there could help me out, it would be appreciate to no end!
Thanks a million!
The Code I am using:
#include <Password.h>
#include <Keypad.h>
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 9, 8, 7, 6 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledPin 13
void setup(){
digitalWrite(ledPin, LOW); // sets the LED on
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);
}
void loop(){
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '#': guessPassword(); break;
default:
password.append(eKey);
}
}}
void guessPassword(){
Serial.print("Guessing password... ");
if (password.evaluate()){
digitalWrite(ledPin,HIGH); //activates garaged door relay
delay(500);
digitalWrite(ledPin,LOW); //turns off door relay after .5 sec
Serial.println("VALID PASSWORD "); //
password.reset(); //resets password after correct entry
}else{
digitalWrite(ledPin,LOW);
Serial.println("INVALID PASSWORD ");
password.reset(); //resets password after INCORRECT entry
}
}
This is the errors I am recileving:
keypad:9: error: variable or field 'keypadEvent' declared void
keypad:9: error: 'KeypadEvent' was not declared in this scope
keypad:6: error: 'Password' does not name a type
keypad:23: error: 'Keypad' does not name a type
keypad.ino: In function 'void setup()':
keypad:31: error: 'keypad' was not declared in this scope
keypad:31: error: 'keypadEvent' was not declared in this scope
keypad.ino: In function 'void loop()':
keypad:36: error: 'keypad' was not declared in this scope
keypad.ino: At global scope:
keypad:40: error: variable or field 'keypadEvent' declared void
keypad:40: error: 'KeypadEvent' was not declared in this scope
You need to put code tags around the code so that we can read it properly on the forum. I don't know if it matters or not, but you don't need another comma at the end of the rows array. It should look like this:
JBTo:
When I try to upload the above code, It gives me the following errors:
keypad:2: error: stray '#' in program
keypad:5: error: variable or field 'keypadEvent' declared void
keypad:5: error: 'KeypadEvent' was not declared in this scope
keypad:2: error: expected unqualified-id before '/' token
keypad:23: error: 'Keypad' does not name a type
keypad.ino: In function 'void setup()':
keypad:31: error: 'keypad' was not declared in this scope
keypad:31: error: 'keypadEvent' was not declared in this scope
keypad.ino: In function 'void loop()':
keypad:36: error: 'keypad' was not declared in this scope
keypad.ino: At global scope:
keypad:40: error: variable or field 'keypadEvent' declared void
keypad:40: error: 'KeypadEvent' was not declared in this scope
Is this a typo, or is it actually like this in your code?
I was able to compile the code above without errors, unless the code above was previously changed. If that is the original sketch, then the issue lies with your library.
Where did you put your library, lets start there. It should be in your MyDocuments as Arduino/libraries/Keypad. Make sure it is also not double foldered. "Keypad/Keypad"
The library file is located in Program files as Arduino/libraries.
But the keypad file is not there. I am looking for it. When I find it should I move it to the library file?
OK THe file is in Mydocuments Arduino/libraries/keypad
but I have several keypad files in there.
Can I delete them all, open a new sketch and save the code fresh?
If the library is in the correct spot then what arduino software version are you using? Make sure the Keypad.h file does not have WProgram.h in it, and if it does then you need to change it to Arduino.h and save it.
If you still get errors then you need to post pictures, screenshots of where the library is and the errors your getting. Make sure the pictures are a reasonable size, nothing like 2000x2000.