Hi guys, first time posting so please be gentle....
if you can find the time i would like some help with a little project for my workshop........i have little C knowledge but i thought buy a starter kit would inflate my interest and it has - until now.
im stuck, i have a 3x4 matrix keypad and just to make it harder i wanted to use the OneWire method using an analog input which works fine - no issues there.
i can use the Password.h library and all is well. i have a larger sketch with RFID and OLED all with no problems - i have become stuck, when trying to use the EEPROM to store and read a password.
like i said i have little knowlege here but i assumed i would need to use a char array and perform some reads in the setup section?
i thought it would just be that but i seem to get nothing?
here is my basic code working fine with no EEPROM commands in it.
#include <Password.h>
Password password = Password("1234" );
byte currentLength = 0;
int threshold[16] = {528, 424, 265, 8, 549, 456, 313, 88, 570, 483, 354, 161, 588, 507, 391, 219};
char keypad[16] = {'1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'};
void setup(){
Serial.begin(9600);
Serial.println("Reset with #");
Serial.print("Enter Passcode: ");
delay(1000);
}
void loop(){
int value = analogRead(A0);
for (int x=0; x<16; x++){
if (abs(value - threshold[x])<5){
char input = keypad[x];
switch (input){
case '#': //Reset Password
password.reset();
currentLength = 0;
Serial.println("Passcode Reset");
delay(150);
break;
case '*': //New Passcode Input
// Perform EEPROM read/write here.
// Create new Void here NewPasscode();
break;
default: //Append any keypress that is not a '#' nor a '*'
password.append(input);
currentLength++;
Serial.print("Enter Passcode: ");
}
for (byte i=0; i<currentLength; i++){ // increase int as digits are pressed
Serial.print('*');
delay(150);
}
Serial.println();
if (currentLength == 4){ //evaluate password when 4 digits have been pressed
if (password.evaluate()){
AccessGranted();
}else{
AccessDenied();
}
}
if (currentLength >=4){ // Reset input/guess after 4 digits have been pressed
password.reset();
currentLength = 0;
Serial.println("Passcode Reset");
}
}
}
}
void AccessGranted(){ // Code here to execute when password is correct.
Serial.println("Access Granted");
delay(3000);
password.reset();
currentLength = 0;
Serial.print("Enter Passcode: ");
}
void AccessDenied(){ // Code here to execute when password is NOT correct.
Serial.println("Access Denied");
delay(3000);
password.reset();
currentLength = 0;
Serial.print("Enter Passcode: ");
}
//NewPasscode(){
// here run the code to....
// 1. validate current passcode.
// 2. input new 4digit passcode.
// 3. buffer this input to confirm it to the next entry.
// 4. enter 4 digits again and compare this to the buffered 4 digits.
// 5. if both entries are equal - store last entry in EEPROM address 0+
// perform EEPROM read if required to update 'Passcode'
Clearly i am wrong to think that the below code should work as it doesnt >:(
#include <Password.h>
#include <EEPROM.h>
char Passcode[4];
Password password = Password(Passcode);
byte currentLength = 0;
int threshold[16] = {528, 424, 265, 8, 549, 456, 313, 88, 570, 483, 354, 161, 588, 507, 391, 219};
char keypad[16] = {'1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'};
void setup(){
Serial.begin(9600);
Serial.println("Reset with #");
Serial.print("Enter Passcode: ");
delay(1000);
Passcode[0] = EEPROM.read(0);
Passcode[1] = EEPROM.read(1);
Passcode[2] = EEPROM.read(2);
Passcode[3] = EEPROM.read(3);
}
i know the EEPROM has 1,3,7,9 stored in the first addresses 0,1,2,3
i assumed that "Passcode[0] would then have '1' from EEPROM address 0 as so on....
then "Passcode [4]" would be the complete array (1379) but the password does accept.
Can anyone tell me where i am going wring with my thinking and point me in the right direction or throw some examples at me for pointers.
any help is greatly appreciated guys.