Hi,
I have some difficulties when recording information in EEPROM struct.
This is the structure I have declared and other declarations that will be used in program.
struct My_EEPROM_Object
{
char password1[5];
char password2[5];
boolean additional_authorization;
char currency[8];
};
char New_password[5]; // array to store new password
char New_verification_password[5]; // array to store new verification password
boolean new_autorization_status;
char new_currency[8]; // array to store currency
struct MyObject{char money_box_opening_password[5]; char authorization_password[5]; boolean confirmation_password;char saved_currency[8];}
This is a part of the code where I’m using keypad to change the passwords:
void Admin_Screen()
{
lcd.clear();
lcd.blink();
lcd.setCursor(0,0);
lcd.print("Enter new password");
while(1)
{
char key = keypad.getKey();
if (key>='0' && key<='9')
{
lcd.print(key);
New_password[new_password_char_count]+=key; // use array to store entered symbols
new_password_char_count++;
}
if (new_password_char_count == 4)
break;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter verification password");
while (1)
{
char key = keypad.getKey();
if (key>='0' && key<='9')
{
lcd.print(key);
New_verification_password[new_verification_password_char_count]+=key;
new_verification_password_char_count++;
}
if (new_verification_password_char_count == 4)
break;
}
lcd.noBlink();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Autorization required?");
lcd.setCursor(0,2);
lcd.print("A - YES);
lcd.setCursor(0,3);
lcd.print("B - NO");
while(1)
{
char key = keypad.getKey();
if (key == 'A')
{
new_autorization_status = true;
break;
}
if (key == 'B')
{
new_autorization_status = false;
break;
}
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Currency");
lcd.setCursor(0,2);
lcd.print("A - Euro");
lcd.setCursor(0,3);
lcd.print("B - Pound");
while(1)
{
char key = keypad.getKey();
if (key == 'A')
{
strcpy(new_currency,"Euro");
break;
}
if (key == 'B')
{
strcpy(new_currency,"Pound");
break;
}
}
float f = money;
int eeAddress = 0;
EEPROM.put(eeAddress,f);
My_EEPROM_Object Memory_Entries =
{
New_password[5],
New_verification_password[5],
new_autorization_status,
new_currency[8],
};
eeAddress += sizeof(float);
EEPROM.put(eeAddress,Memory_Entries);
MyObject customVar;
lcd.clear();
lcd.setCursor(0,0);
EEPROM.get(eeAddress, customVar);
lcd.print(customVar.money_box_opening_password);
lcd.setCursor(0,1);
lcd.print(customVar. authorization_password);
lcd.setCursor(0,2);
lcd.print(customVar. confirmation_password);
lcd.setCursor(0,3);
lcd.print(customVar.saved_currency);
The problem I have is with two saved passwords(money_box_opening_password and authorization_password). When I’m trying to read saved values from EEPROM , I’m just getting weird symbols on LCD display (not the values that were entered i.e 1234).
Confirmation_password and Saved_currency contain correct values.
Where I’m making a mistake? I think that the issue is with the arrays and how they are saved in memory.
My_EEPROM_Object Memory_Entries =
{
New_password[5],
New_verification_password[5],
new_autorization_status,
new_currency[8],
};
Another thing is that when I recorded values into My_EEPROM_Object Memory_Entries as below, everything was recorded correctly. The correct values were read from EEPROM and displayed on LCD.
My_EEPROM_Object Memory_Entries =
{
"1234",
"7777",
1,
"Euro",
};
I would really appreciate any help in this case as I’m stuck with this problem and I don’t really know how to fix it.
Thank you in advance