all the files are in same folder but fails to upload i get error!
#include <Keypad.h>
#include <Password.h>
// include <Password.h> // http://www.arduino.cc/playground/uploads/Code/Password.zip
// include <Keypad.h> // http://www.arduino.cc/playground/uploads/Code/Keypad.zip
//* is to validate password
//# is to reset password attempt
/////////////////////////////////////////////////////////////////
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{
'1','2','3','A' }
,
{
'4','5','6','B' }
,
{
'7','8','9','C' }
,
{
'*','0','#','D' }
};
byte rowPins[ROWS] = {
9,8,7,6 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = {
5,4,3,2, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}
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 '*':
checkPassword();
break;
case '#':
password.reset();
break;
default:
password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
// Serial.println("Success");
Serial.println("Correct");
// do unlock here
//Add code to run if it works
}
else{
Serial.println("Wrong");
//add code to run if it did not work
}
}
DoorPassCheck_2014.ino:16:18: error: variable or field ‘keypadEvent’ declared void
DoorPassCheck_2014.ino:16:18: error: ‘KeypadEvent’ was not declared in this scope
DoorPassCheck_2014.ino:13:1: error: ‘include’ does not name a type
DoorPassCheck_2014.ino:42:1: error: ‘Keypad’ does not name a type
DoorPassCheck_2014.ino: In function ‘void setup()’:
DoorPassCheck_2014.ino:47:3: error: ‘keypad’ was not declared in this scope
DoorPassCheck_2014.ino:47:27: error: ‘keypadEvent’ was not declared in this scope
DoorPassCheck_2014.ino: In function ‘void loop()’:
DoorPassCheck_2014.ino:51:3: error: ‘keypad’ was not declared in this scope
DoorPassCheck_2014.ino: At global scope:
DoorPassCheck_2014.ino:55:18: error: variable or field ‘keypadEvent’ declared void
DoorPassCheck_2014.ino:55:18: error: ‘KeypadEvent’ was not declared in this scope
when i take out the# include lines
and this error when i leave the # in place
Password.cpp:113: first defined here
collect2: error: ld returned 1 exit status
the password.cpp file is as follows (whats wrong with it)?
/*
||
|| @file Password.cpp
|| @version 1.2
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| 4/5/2012 Updates Nathan Sobieck: Nathan@Sobisource.com
|| Now v1.2 Arduino IDE v1.0 With BAckwards compatibility
||
|| @description
|| | Handle passwords easily
|| #
||
|| @license
|| | This library is free software; you can redistribute it and/or
|| | modify it under the terms of the GNU Lesser General Public
|| | License as published by the Free Software Foundation; version
|| | 2.1 of the License.
|| |
|| | This library is distributed in the hope that it will be useful,
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|| | Lesser General Public License for more details.
|| |
|| | You should have received a copy of the GNU Lesser General Public
|| | License along with this library; if not, write to the Free Software
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|| #
||
*/
#include "Password.h"
//construct object in memory, set all variables
Password::Password(char* pass){
set( pass );
reset();
}
//set the password
void Password::set(char* pass){
target = pass;
}
//evaluate a string, is it equal to the password?
bool Password::is(char* pass){
byte i=0;
while (*pass && i<MAX_PASSWORD_LENGTH){
guess[i] = pass[i];
i++;
}
return evaluate();
}
//append a char to the guessed password
bool Password::append(char character){
if (currentIndex+1==MAX_PASSWORD_LENGTH){
return false;
}else{
guess[currentIndex++] = character;
guess[currentIndex] = STRING_TERMINATOR; //ensure a valid c string
}
return true;
}
//reset the guessed password, one can guess again
void Password::reset(){
currentIndex = 0;
guess[currentIndex] = STRING_TERMINATOR;
}
//is the current guessed password equal to the target password?
bool Password::evaluate(){
char pass = target[0];
char guessed = guess[0];
for (byte i=1; i<MAX_PASSWORD_LENGTH; i++){
//check if guessed char is equal to the password char
if (pass==STRING_TERMINATOR && guessed==STRING_TERMINATOR){
return true; //both strings ended and all previous characters are equal
}else if (pass!=guessed || pass==STRING_TERMINATOR || guessed==STRING_TERMINATOR){
return false; //difference OR end of string has been reached
}
//read next char
pass = target[i];
guessed = guess[i];
}
return false; //a 'true' condition has not been met
}
//set password using operator =
Password &Password::operator=(char* pass){
set( pass );
return *this;
}
//test password using ==
bool Password::operator==(char* pass){
return is( pass );
}
//test password using !=
bool Password::operator!=(char* pass){
return !is( pass );
}
//append to currently guessed password using operator <<
Password &Password::operator<<(char character){
append( character );
return *this;
}
/*
|| @changelog
|| | 2009-06-17 - Alexander Brevig : Added assignment operator =, equality operators == != and insertion operator <<
|| | 2009-06-17 - Alexander Brevig : Initial Release
|| #
*/