Hello,
I am trying to write some strings to eeprom using put and get approach abd trying to use the value ofstored in an array to the custom object but it is nbot writing to epromm if I hard code the values to the object it works works
Here is my sample code
#include <EEPROM.h>
char LocoAddress[4][6] = {"1830", "3", "999", "4444"};
struct MyObject {
char loc0[10];
char loc1[10];
char loc2[10];
char loc3[10];
};
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
secondTest();
writtoeprom();
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
}
void loop() {
/* Empty loop */
}
void writtoeprom(){
//float f = 123.456f; //Variable to store in EEPROM.
int eeAddress = 0; //Location we want the data to be put.
/* this works
MyObject customVar = {
"BLABLA0",
"BLABLA1",
"BLABLA2",
"BLABLA3"
};
*/
MyObject customVar = {
LocoAddress[0],
LocoAddress[1],
LocoAddress[2],
LocoAddress[3]
};
// eeAddress += sizeof(float); //Move address to the next byte after float 'f'.
EEPROM.put(eeAddress, customVar);
//secondTest();
Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!");
}
void secondTest() {
int eeAddress = sizeof(float); //Move address to the next byte after float 'f'.
MyObject customVar; //Variable to store custom object read from EEPROM.
EEPROM.get(eeAddress, customVar);
Serial.println("Read custom object from EEPROM: ");
Serial.println(customVar.loc0);
Serial.println(customVar.loc1);
Serial.println(customVar.loc2);
Serial.println(customVar.loc3);
}