saving keypad password to internal EEPROM

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,

I cannot seem to save the key pressed as an integer though

Unless you have more than 255 keys, there is no reason to have the value stored as an int. You don't have more than 255 keys, do you?

Learn to use the proper size variables. None of the stuff you are doing with EEPROM or the keypad needs ints. The types should all be byte.

could you shed any light on how to use byte?

http://www.arduino-hacks.com/converting-integer-to-character-vice-versa/ I just found this link , I am planning on trying that, do you think it may work ?

could you shed any light on how to use byte?

byte thisIsAByte;

What more do you need? The getKey() function returns a char (which you discard) which is the same size as a byte. The EEPROM.write() function takes a byte. The EEPROM.read() function returns a byte.

I don't understand what you are writing to EEPROM now. Writing the KeypadEvent to EEPROM is not the same as writing the key that was pressed as part of that event.

Paul
I have only ever used integers in code that I have written , Im guna have a go at bytes instead. apparently im dumb and should have thought of that,

What I want to store in eeprom is the result of the user pressing a sequence of keys,

What I want to store in eeprom is the result of the user pressing a sequence of keys,

Is that "result" a string? Is it a collection of characters in an array? Is each character to be saved as entered, or is the collection to be saved when the collection is complete?

as of now I only have a collection of characters that are inputted one at a time, Using the method in the link i posted I have now at least been able to save one character from a button push into the place i expected it to be in eeprom.

the following step is to put a sequence of characters into an array, or feed them into eeprom one at a time and read them back one at a time.