The intention is to read a 4 position password out of an EEPROM.
The EEPROM has :
• Position [0] : pincheck → if this is 1 then a password has been selected and stored on a previous run. If it contains 0 then a new password of 4 characters must be chosen and stored in the EEPROM positions 1 to 4
• Positions [1 to 4] : a password, it is factoryloaded with “0000” when the first position of the EEPROM [0] is “0”. After a password was entered in this run or before it contains the four digit password.
When a 4 digit password is entered followed by “*” the the function checkPasswordSTAR() runs.
If the first EEPROM position (pincheck) = 0 then I want the entry given via the keyboard used as the new set password.
Now I’m totally lost with this String?? Char?? Password…. I’m new to programming and this is still a bit “in the clouds” for me.
Thanks for helping.
My questions :
• How do I spilt up the new password to be able to write it in The EEPROM positions 1 to 4
• How do I use the password.set function to set the new password?
//http://www.arduino.cc/playground/uploads/Code/Password.zip
//http://www.arduino.cc/playground/uploads/Code/Keypad.zip
#include <Password.h>
#include <Keypad.h>
#include <EEPROM.h>
Password password = Password( "0000" );
const byte ROWS = 4; const byte COLS = 4;
char keys[ROWS][COLS] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
byte rowPins[ROWS] = { 2,3,4,5 }; byte colPins[COLS] = { 6,7,8,9, };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
//Read EEPROM
String pincheck = String (EEPROM.read(0));
String pin1 = String (EEPROM.read(1));
String pin2 = String (EEPROM.read(2));
String pin3 = String (EEPROM.read(3));
String pin4 = String (EEPROM.read(4));
keypad.addEventListener(keypadEvent); //event checker
void loop(){keypad.getKey();}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
switch (eKey){
case '*': checkPasswordSTAR(); break;
default: password.append(eKey);}}}
void checkPasswordSTAR(){
// I suppose I need to check here if the field pincheck = 0 here and then do the writing to the EEPROM.
if (password.evaluate()){
Serial.println("password OK");
else {
Serial.println("* password incorrect");
password.reset();}
}