EEPROM.put + constant


Are these codes # 1 or # 2 correct? I can't find any answer...

Variant 1:

const byte MyConstant = 12;
int eeAddress = 0;
EEPROM.put(eeAddress, MyConstant);

Variant 2:

int eeAddress = 0;
EEPROM.put(eeAddress, 12);

I know that this one with a variable is better, but it uses the SRAM:

Variant 3:

byte MyVariable = 12;
int eeAddress = 0;
EEPROM.put(eeAddress, MyVariable);

Sorry if this is a frequent topic, but I tried to find an explanation and didn't find any.


Hi @fred_76

If you use EEPROMs larger than 255 bytes, the Variant 3: can't be used if it's addressing above 256, as the address will be more than one byte, but if it's addressing below, I don't see why it doesn't work.

RV mineirin


Variant 3 uses an int address.

Variant 1:
Why would you put a const value in EEPROM ?

you are right.
I think that i have to change my glasses.... kk

Variant 3 : I know it works, don’t reply on this one.

Variant 1 : I’ m storing a known and predefined value to make sure the EEPROM contains the data. When the value at address 0 doesn’t contain the expected value (here = 12), it means the EEPROM has to be loaded with the default data.