I tried to resolve it in severals and differents ways but I am turning around ... i think i am lost with it...
The system is capable of holding an array of four digits.
The array is cleared when the system starts and after each entry (pressing the Valdiate key)
When the user enters a digits on a keypad it is appended to the array and the digits are shown on a display
When the user presses the Cancel (delete) button the array and display are cleared
When the Correct (Backspace) button is pressed, the must recently entered digit is erased and the display is updated
If more than 4 digits are pressed, (explain here what you want to happen) .... save only the first 4 digits after 'C' validate key is pressed
When the Validate (enter) key is pressed, the digits are processed (saved to eeprom, validated,?)
This is exactly what what the system must do.
That is where I am with this sketch:
#include <Keypad.h>
#include <Time.h>
#include <EEPROM.h>
int i = 0; // variable to keep track of number of keys pressed);
char sequence [4] = {0, 0, 0, 0}; // 4 digits
char key;
char Correct = 'A'; // Correct the last digit (Backspace)
char Cancel = 'B'; // Cancel (Clear) the current sequence
char Validate = 'C'; // Validate by "saving in eeprom"
char Read = 'D'; // Read all sequences of digits from eeprom
boolean correctCombo = false; // Make a boolean to store whether the correct sequence is entered
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
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}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;
void setup(){
Serial.begin(9600);
Serial.println("KEYPAD: ENTER DIGITS");
pinMode(ledPin, OUTPUT); // sets the digital pin as output
digitalWrite(ledPin, HIGH); // sets the LED on
if (key == 'D') {
Serial.println("address \t sequence \t i");
for (i=0; i < 1024; i++) {
sequence [i] = EEPROM.read(i);
Serial.print(i);
Serial.print("\t");
Serial.println(sequence [i]);
Serial.print("\t");
sequence [i] = EEPROM.read(i);
Serial.println(sequence [i]);
Serial.println();
delay(500);
}
}
}
void loop(){
if (i == 4){
check();
}
char key = keypad.getKey();
if(key != NO_KEY)
{
sequence[i] = key;
i++;
sequence[i] = '\0';
Serial.print(key);
}
if (key == 'C') // Validate by "saving in eeprom"
{
for (i = 0; i < 1024; i++)
EEPROM.write(i, sequence[i]);
}
if (key == 'D') // Read all sequences of digits from eeprom
{
for (i=0; i < 1024; i++)
sequence [i] = EEPROM.read(i);
Serial.println(i);
Serial.println(sequence [i]);
delay(500);
if (key == 'A') { } // Correct the last digit (Backspace)
if (key == 'B') { } // Cancel (Clear) the current sequence
}
}
void check()
{
if (strcmp(sequence, sequence) == 0){
Serial.println( "\t" "Valid");
correctCombo = true;
i = 0;
}
}
Here the serial output when sequences are pressed:
KEYPAD: ENTER DIGITS
5533 Valid
3333 Valid
3333 Valid
3221 Valid
1122 Valid
2333 Valid
C2222222222222333333333333333338888888D1024
2
D1024
D
D1024
D
D1024
D
D1024
D
D1024
D
ABBBAAABBD1024
A
D1024
D
D1024
D
D1024
D
I can not move forward... i can't save sequences on eeprom... Where are all my mistakes??