Hi, sorry if this make double post.. I try to find in this forum but have no result. Apologize my mistake.
I want to save value from EEPROM to variable that i define before, but result is not expected, just print a char that no relevant with value from EEPROM.
Here my code:
/*
Using: Arduino Mega 2560 clone
Library: EEPROM Built-In by Arduino, Christopher Andrews Version 2.0.0
*/
#include <EEPROM.h>
const byte eeAddress = 0;
char mytest;
struct MyObject {
char my_el_1[10];
char my_el_2[10];
char my_el_3[20];
char my_el_4[20];
float my_fl_1;
float my_fl_2;
char my_c_1[20];
char my_c_2[50];
char my_c_3[50];
byte my_b_1;
char my_c_4[15];
byte my_b_2;
byte my_b_3;
byte my_b_4;
};
void setup() {
Serial.begin(9600);
// eeprom clear
cls_eeprom();
// eeprom put
to_eeprom();
// eeprom get
from_eeprom();
}
void cls_eeprom() {
pinMode(13, OUTPUT);
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
digitalWrite(13, HIGH);
}
void to_eeprom() {
MyObject customVar1 = {
"RED",
"YELLOW",
"BLUE-WHITE",
"NATURAL GLOW",
1.80f,
1.24f,
"internet",
"www.mywebsite.com",
"/colour/check.php",
1,
"1234567890",
1,
60,
1
};
EEPROM.put(eeAddress, customVar1);
Serial.println("Saving to EEPROM: OK");
}
void from_eeprom() {
MyObject customVar2;
EEPROM.get(eeAddress, customVar2);
Serial.println(customVar2.my_el_4); // ---> this print 'NATURAL GLOW' without quote as expected
// change mytest
mytest = (customVar2.my_el_4);
Serial.print("mytest: "); Serial.println(mytest); // ---> just print 'mytest: S' without quote
}
void loop() {
/** Empty loop. **/
}
Thanks for any advice..
(Bol)