Ho creato tre matrici e due funzioni per leggere o scrivere i valori in EEPROM, nelle funzioni ci sono dei comandi per inviare su un normalissimo display LCD, a scopo di debug, i dati scritti o letti, in scrittura semprerebbe tutto ok ma quando provo a leggere ottengo solo degli zero.
sto utilizzando un display nextion.
Per praticità avendo tre pagine ciascuna con sedici btn ho fatto si che gli ID dei btn siano da 1..16 e le matrici da 17 byte non utilizzando il primo, ogni pagina ha la sua matrice, quindi pagina uno usa MP1, pagina due MP2 e così via.
I parametri che invio alle funzioni sono esatti
** Dichiarazione matrici
uint8_t MP1[17][3]; //banco memorie Page 1 [L] [C] [Rly]
uint8_t MP2[17][3]; //banco memorie Page 1 [L] [C] [Rly]
uint8_t MP3[17][3]; //banco memorie Page 1 [L] [C] [Rly]
void R_mem(int page, int btn)
{
if (page == 1)
{
C_pos = EEPROM.read(MP1[btn][0]);
L_pos = EEPROM.read(MP1[btn][1]);
mode_status = EEPROM.read(MP1[btn][2]);
}
if (page == 2)
{
C_pos = EEPROM.read(MP2[btn][0]);
L_pos = EEPROM.read(MP2[btn][1]);
mode_status = EEPROM.read(MP2[btn][2]);
}
if (page == 3)
{
C_pos = EEPROM.read(MP3[btn][0]);
L_pos = EEPROM.read(MP3[btn][1]);
mode_status = EEPROM.read(MP3[btn][2]);
}
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("R >M-"+ String(page) + "-" + String (btn) +"-"+ String(EEPROM.read(MP1[btn][0])) + "-" +String(L_pos)+ "-"+ String(mode_status));
}
void W_mem(int page, int btn, int C, int L, int mode)
{
if (page == 1)
{
EEPROM.write(MP1[btn][0],C);
delay (10);
EEPROM.write(MP1[btn][1],L);
delay (10);
EEPROM.write(MP1[btn][2],mode);
delay (10);
}
if (page == 2)
{
EEPROM.write(MP2[btn][0],C);
EEPROM.write(MP2[btn][1],L);
EEPROM.write(MP2[btn][2],mode);
}
if (page == 3)
{
EEPROM.write(MP3[btn][0],C);
EEPROM.write(MP3[btn][1],L);
EEPROM.write(MP3[btn][2],mode);
}
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("W>M-"+ String(page) + "-" + String (btn)+ "-" + String(C) + "-" + String(L) + "-" +String(mode));
}
Onestamente non riesco a capire se e dove sbaglio, anzi escluderei il se.
Grazie per l'attenzione