Hi guys,
First off, i'm an offshore electrical engineer however electronics (particularly Arduino) is not something i've spent much time with. More used to heavy machinery, 24kV switchboards and 11kV propulsion motors on ships etc.
Anyway, excuses aside...
I've been tasked to develop a secure entry system into a hazardous area on board a ship, utilising a keypad and servo motor in the first instance. Fortunately i found the vast Arduino online support network early on and have managed to pick up enough to write/borrow/chop a sketch together.
However, i'm having trouble when i verify my sketch, i get the following errors...
Programme_Attempt_2:9: error: variable or field 'keypadEvent' declared void
Programme_Attempt_2:9: error: 'KeypadEvent' was not declared in this scope
Programme_Attempt_2:7: error: 'Password' does not name a type
Programme_Attempt_2:25: error: 'Keypad' does not name a type
Programme_Attempt_2.ino: In function 'void setup()':
Programme_Attempt_2:35: error: 'keypad' was not declared in this scope
Programme_Attempt_2:35: error: 'keypadEvent' was not declared in this scope
Programme_Attempt_2.ino: In function 'void loop()':
Programme_Attempt_2:39: error: 'keypad' was not declared in this scope
Programme_Attempt_2.ino: At global scope:
Programme_Attempt_2:43: error: variable or field 'keypadEvent' declared void
Programme_Attempt_2:43: error: 'KeypadEvent' was not declared in this scope
From the little i know, it looks or seems to me like the sketch isn't finding the Keypad librarie? It IS in the libraries folder along with 2 other libraries (servo and password) which seem to be working.
I have attached the code below if it helps anyone help me.
Any help is much appreciated,
Colin.
#include <Keypad.h> //instructs to use keypad library
#include <Password.h> //instructs to use password library
#include <Servo.h> //instructs to use servo library
Servo myservo; //declares servo
Password password = Password( "1, 2, 3, 4" ); //password to unlock door/start servo, can be changed.
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','#'}
};
byte rowPins[ROWS] = { 5, 4, 3, 2 };// Connect keypad ROW1, ROW2, ROW3 and ROW4 to these Arduino pins.
byte colPins[COLS] = { 8, 7, 6 };// Connect keypad COL1, COL2 and COL3 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
Serial.print(254);
Serial.print(0x01);
delay(200);
pinMode(11, OUTPUT); //Green light
pinMode(12, OUTPUT); //Red light
myservo.attach(13); //Servo on digital pin 9 //servo
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
void loop(){
keypad.getKey();
myservo.write(0);
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Enter: ");
Serial.println(eKey);
delay(10);
Serial.print(254);
switch (eKey){
case 'A': checkPassword(); delay(1); break;
case 'B': password.reset(); delay(1); break;
default: password.append(eKey); delay(1);
}
}
}
void checkPassword(){
if (password.evaluate()){ //if password is right open door/turn servo 160deg
Serial.println("Accepted");
Serial.print(254);delay(10);
//Add code to run if it works
myservo.write(5); //160deg
digitalWrite(11, HIGH);//turn on
delay(500);
digitalWrite(11, LOW);// turn off
}else{
Serial.println("Denied"); //if passwords wrong keep door locked/servo motionless
Serial.print(254);delay(10);
//add code to run if it did not work
myservo.write(0);
digitalWrite(12, HIGH); //turn on
delay(500);
digitalWrite(12, LOW);//turn off
}
}