how to fix this eeprom problem ??

i need your help please to achieve this result :

  • Set a
  • Set b
  • x = a+5(b-1)

eeprom address = x

//**************************

eeprom.update (x,b)

// **************************

  • set x to view value stored in :

eeprom.read (x)

The prob of the code below is :

  • all value return to 225 after power down

  • and when i select x the view data in , the value is the same for all address (“for all x)”

#include <Keypad.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>

//int address = 0;
int H =0 ;

LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; 
const byte COLS = 4; 

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6}; 
byte colPins[COLS] = {5, 4, 3, 2}; 

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 

int a = 0 ;

int b = 0 ;

int x =0 ;
int aa= 0 ;
int bb = 0;
int p = 0 ;
int k = 0 ;


 void setup(){
  Serial.begin(9600);
}
  
void loop(){

//Serial.println (a);
  char menu = customKeypad.getKey();
      if(menu!= NO_KEY)
      {
        switch(menu)
        {
          case 'A':
          Serial.println ("set a");
         // customKeypad.waitForKey();
          
           a = customKeypad.waitForKey();
          Serial.println (a-48);
          
          break;

          case 'B':
          Serial.println ("set b");
          b = customKeypad.waitForKey();
          Serial.println (b-48);
          break;

          case 'C':
          Serial.print ("*X :::: ");
           aa = a-48 ;
           bb = b-48 ;

          
          x = aa+(5*(bb-1)) ;
          Serial.println (x);
           EEPROM.update(x, bb);
          
           break;
           
          case 'D':
          
          Serial.println ("set add X to view value in : ");
          p = customKeypad.waitForKey();
          k = p - 48 ;

          Serial.print ("the selected adress is :");
          Serial.println (k);
          delay (1000);
//          
           Serial.println ();

//          
          H = EEPROM.read(x);
          Serial.print ("the value stored in x adress is  :");
          Serial.println(H);
           break;
          }
        
        }

:slight_smile: thank you so much problem solved

  • i cleared the eeprom

  • then replace "x" with "k" in the last line