hey im back, when i run this code none of the default values are correct?
#include <EEPROM.h>
// __attribute__ ((packed)) is to force the compiler to use the minimum required memory to represent the type
// see https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Type-Attributes.html
struct __attribute__ ((packed)) _paramS {
unsigned long minimumT;
unsigned long maximumT;
unsigned long maximumA;
unsigned long maximumB;
unsigned long t1ontimeDAY; /////
unsigned long t1offtimeDAY;
unsigned long t2ontimeDAY; /////
unsigned long t2offtimeDAY;
unsigned long t3ontimeDAY; /////
unsigned long t3offtimeDAY;
unsigned long t1ontimeNIGHT; /////
unsigned long t1offtimeNIGHT;
unsigned long t2ontimeNIGHT; /////
unsigned long t2offtimeNIGHT;
unsigned long t3ontimeNIGHT; /////
unsigned long t3offtimeNIGHT;
} myParamters;
const uint32_t keyword = 0xDEADBEEF;
const uint16_t keywordAddress = 0x00;
const uint16_t paramAddress = keywordAddress + sizeof(keyword);
void printParam()
{
Serial.println(F("\n************* PARAMS *************"));
Serial.print(F("Temp minn =\t")); Serial.println(myParamters.t1ontimeDAY);
Serial.print(F("Temp maxx =\t")); Serial.println(myParamters.t2ontimeDAY);
Serial.print(F("Temp max =\t")); Serial.println(myParamters.maximumB);
}
void saveParam()
{
EEPROM.put(keywordAddress, keyword);
EEPROM.put(paramAddress, myParamters);
}
void getParam()
{
uint32_t tmpKey;
EEPROM.get(keywordAddress, tmpKey);
if (tmpKey == keyword) {
EEPROM.get(paramAddress, myParamters); // EEPROM was already initialized OK to read
} else {
// First run on this arduino, memory was never initialized. so establish default values
myParamters.t1ontimeDAY = 1002001;
myParamters.t1offtimeDAY = 1002002;
myParamters.t2ontimeDAY = 1002001;
myParamters.t2offtimeDAY = 1002002;
myParamters.t3ontimeDAY = 1002001;
myParamters.t3offtimeDAY = 1002002;
myParamters.t1ontimeNIGHT = 1002001;
myParamters.t1offtimeNIGHT = 1002002;
myParamters.t2ontimeNIGHT = 1002001;
myParamters.t2offtimeNIGHT = 1002002;
myParamters.t3ontimeNIGHT = 1002001;
myParamters.t3offtimeNIGHT = 1002002;
saveParam();
}
}
void setup() {
Serial.begin(9600);
getParam(); // first run will establish the defaults in EEPROM
printParam(); // see what the values are
myParamters.minimumT = 1002001; // change one of the parameters
myParamters.maximumB = 1002011; // change one of the parameters
saveParam(); // save it
printParam(); // show it has been saved
}
void loop() {}
or is it that this part don't run unless there is a problem reading from eeprom?
EEPROM.get(keywordAddress, tmpKey);
if (tmpKey == keyword) {
EEPROM.get(paramAddress, myParamters); // EEPROM was already initialized OK to read
} else {