#include <EEPROM.h>
//const int COUNT_ADDR1 = 0;
//const int COUNT_ADDR2 = 5;
//int value = 0;
char password[7];
int index = -1;
void writepassword() {
Serial.print ("pw letta: ");
Serial.println(password);
EEPROM.put(0,password);
}
void readpassword(){
char pippo[7];
EEPROM.get(0,pippo);
Serial.print ("pw letta da eprom: ");
Serial.println(pippo);
}
void setup() {
Serial.begin(9600);
//byte hiByte = EEPROM.read(COUNT_ADDR1);
//byte lwByte = EEPROM.read(COUNT_ADDR2);
//int prevCount = word(hiByte, lwByte);
//Serial.print("In the previous session, your Arduino counted ");
//Serial.print(prevCount);
Serial.println(" events");
}
void loop() {
if ( Serial.available()) {
char ch = Serial.read();
if ( ch >= '0' && ch <= '9') {
index ++;
password[index] = ch;
if (index == 5) {
password[index + 1] = 0;
Serial.println();
writepassword();
index = -1;
}
//value = value + (ch - '0');
//Serial.print("value =");
//Serial.print(ch);
}
/*if ( ch == 'w' ) {
byte hi = highByte(value);
byte lw = lowByte(value);
EEPROM.write(COUNT_ADDR1, hi);
EEPROM.write(COUNT_ADDR2, lw);
Serial.println("value written on EEPROM");
value = 0;
}
if ( ch == 'r') {
byte hi = EEPROM.read(COUNT_ADDR1);
byte lw = EEPROM.read(COUNT_ADDR2);
int v = word(hi, lw);
Serial.print("value read on EEPROM: ");
Serial.println(v);
}*/
if ( ch == 'p') {
readpassword();// da sistemare
/*byte hi = EEPROM.write(COUNT_ADDR1);
byte lw = EEPROM.write(COUNT_ADDR2);
char v = word(hi, lw);
Serial.print("value read on EEPROM: ");
Serial.println(v);*/
}
}
}