Hi
/*
|| Simple Password Entry Using Matrix Keypad
|| 4/5/2012 Updates Nathan Sobieck: Nathan@Sobisource.com
||
*/
//* is to validate password
//# is to reset password attempt
/////////////////////////////////////////////////////////////////
#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip
#include <EEPROM.h>
Password password = Password( "1234" );
//////password stuff
int ee1=0;
int ee2=0;
int ee3=0;
int ee4=0;
int EEsize = 5;
int zz;
int password2 =0;
int pass1=1;
int pass2=2;
int pass3=6;
int pass4=4;
int in1=0;
int in2=0;
int in3=0;
int in4=0;
int Stop =0;
char temp1=0;
int temp2=0;
int temp3=0;
int temp4=0;
//////////////////////////////////////
const int ledPin = 13;
int ledState = LOW;
long interval = 200;
long interval2 = 2000;
unsigned long currentMillis = 0;
long previousMillis = 0;
long previousMillis2 = 0;
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = { 4,5,7,9 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 3,6,8 };// 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);
//////////password write (only needed once )
// EEPROM.write(1, pass1);
// EEPROM.write(2, pass2);
// EEPROM.write(3, pass3);
// EEPROM.write(4, pass4);
///////////////Password read
ee1 = EEPROM.read(1);
ee2 = EEPROM.read(2);
ee3 = EEPROM.read(3);
ee4 = EEPROM.read(4);
////////////password calculation
password2=((ee1*1000)+(ee2*100)+(ee3*10)+(ee4));
////////////password print
Serial.println("password");
Serial.println(password2);
//////////////////////////////////////////////////////////////////
pinMode(ledPin, OUTPUT);
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);
Serial.println("temp1");
temp1=eKey;
Serial.println(eKey);
Serial.println(temp1);
if (Stop==0){
EEPROM.write(2, temp1);
digitalWrite(ledPin,HIGH);
Stop=1;
}
switch (eKey){
case '*': checkPassword(); break;
case '#': password.reset(); break;
case '0': passwordwrite(); //break;
default: password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
Serial.println("Success");
}else{
Serial.println("Wrong");
//add code to run if it did not work
}
}
void passwordwrite(){
Serial.println("please enter new password");
password.set("2345");
}
I have this code, I have taken the password and eeprom examples from the playground , I have succesfully written one digit into the eeprom and have been able to take those digits out and construct a password from them.
The main bulk of the code is doing what I expect, I can see the keystroke from a 12 button pinpad on the serial monitor, and it corresponds to the key pressed.
I cannot seem to save the key pressed as an integer though, I want to do this in order to then send it over to eeprom as part of a password changing routine.
I asume I have some problem with the format that the library is using and wanting to save that as an integer, if i change my variable temp1 from int to char, i can at least print the same number over serial that I am expecting to see, but then when I save that to eeprom it doesnt only affect the block that I think I am writing it to
"EEPROM.write(2, temp1);"
this line causes the first two digits in my password to change, the password is calc'd in setup ,
help would be appreciated,