Hello Friends
I am working on a simple sketch that to write and to read data to the internal uno EEPROM
the problem that when I save the first Variable fore the address one , I read it correctly
until when I save the second Variable .......
then the two Variables Become the same !!!
#include <Keypad.h>
#include<LiquidCrystal.h>
#include<EEPROM.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
/////////////////////////////////////////////////////////////////////
char customKey=0; // CustomKey Pad val
char customKey2=0; // CustomKey2 Pad val
int j=0; // price1 address TO EEPROM
char eep1[5]; // price1 val TO EEPROM
char* p1=EEPROM.get(j,eep1); // Read from Price1 EEPROM
float par=atof (p1); // EEPROM Char to float Price1
float prize=par*10; // Price1 DEC to INT
int r=0; // price2 address TO EEPROM
char eep2[5]; // price2 val TO EEPROM
char* p2=EEPROM.get(r,eep2); // Read from Price2 EEPROM
float par2=atof (p2); // EEPROM Char to float Price2
float prize2=par2*10; // Price2 DEC to INT
const byte ROWS = 4;
const byte COLS = 4;
char Keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'.','0','#','D'}
};
byte rowPins[ROWS] = {3,2,A5,A4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A3,A2,A1,A0}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad myKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS);
/////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Funy Test");
lcd.setCursor(0,1);
lcd.print(prize); //to print the price1 as int on the screen
lcd.setCursor(8,1);
lcd.print(prize2); //to print the price1 as int on the screen
}
/////////////////////////////////////////////////////////////////////
void(*resetFunc)(void)=0;
void loop(){
char key = myKeypad.getKey();
if (key != NO_KEY){
delay(60);
switch (key){
case 'A': menu();break;
case 'B': break;
case 'C': break;
case 'D': break;
case '#': break;
case '.': break;
}}
}
/////////////////////////////////////////////////////////////////////
void price1(){
lcd.clear();
lcd.print("A4 Price:");
lcd.setCursor(0,1);
j;
while(j<5){
char customKey = myKeypad.getKey();
if((customKey=='1')or(customKey=='2')or(customKey=='3')or(customKey=='4')or(customKey=='5')or(customKey=='6')
or(customKey=='7')or(customKey=='8')or(customKey=='9')or(customKey=='0')or(customKey=='.')){
eep1[j]=customKey;
lcd.print(customKey);
EEPROM.update(j,eep1[j]);
j++;
}
else if(customKey=='B'){
menu();
break;}
}
lcd.print(" >> Done...");
delay(2000);
resetFunc(); // I use the reset function to update the new entry on lcd
}
/////////////////////////////////////////////////////////////////////
void price2(){
lcd.clear();
lcd.print("A3 Price:");
lcd.setCursor(0,1);
r;
while(r<5){
char customKey2 = myKeypad.getKey();
if((customKey2=='1')or(customKey2=='2')or(customKey2=='3')or(customKey2=='4')or(customKey2=='5')or(customKey2=='6')
or(customKey2=='7')or(customKey2=='8')or(customKey2=='9')or(customKey2=='0')or(customKey2=='.')){
eep2[r]=customKey2;
lcd.print(customKey2);
EEPROM.update(r,eep2[r]);
r++;
}
else if(customKey2=='B'){
menu();
break;}
}
lcd.print(" >> Done...");
delay(2000);
resetFunc(); // I use the reset function to update the new entry on lcd
}
/////////////////////////////////////////////////////////////////////
void counter(){
lcd.clear();
lcd.print ("Total:");
}
/////////////////////////////////////////////////////////////////////
void menu(){
lcd.clear();
lcd.print ("[1]A4");
lcd.setCursor(0,1);
lcd.print ("[2]A3");
lcd.setCursor(6,0);
lcd.print ("[3]Counter");
lcd.setCursor(6,1);
lcd.print ("[B]Exit");
int c=1;
while(c){
char customKey = myKeypad.getKey();
if(customKey=='1')
price1();
if(customKey=='2')
price2();
if(customKey=='3')
counter();
else if(customKey=='B'){
setup();
break;
}
}
}
/////////////////////////////////////////////////////////////////////
Sooooooo where is the problem??????