Question on EEPROM.writeAnything

Hi all,

I have a very quick question regarding EEPROM.writeAnything and EEPROM.readAnything. I serched for the answer online and on the playground as well but without success.

I want to achieve the following. In void loop() I have a series of functions. Every day at 11pm I want to save certain values to the EEPROM. Say that I just saved a bunch of values on the EEPROM today at 11pm. Tomorrow I want to save the same values at 11pm by replacing/deleting the previous ones. At the same time, during setup I want to read the values from EEPROM. Is the following code accomplishing this?

float a;
float b;
float c;
eeprom_address = 0;


void setup()
{
    EEPROM_readAnything(eeprom_address, a);
    EEPROM_readAnything(eeprom_address, b);
    EEPROM_readAnything(eeprom_address, c);
}

void loop()
{
    void Write_EEPROM()
    {
       if(hour() == 23)
       {
         eeprom_address += EEPROM_writeAnything(eeprom_address, a);
         eeprom_address += EEPROM_writeAnything(eeprom_address, b);
         eeprom_address += EEPROM_writeAnything(eeprom_address, c);
       }
    }
}

You will notice that I haven't hardcoded the address to write to, it just starts at 0.

Considering that all my variables are float (so 4 bytes on the eeprom), my understanding with the above code is that every day at 11pm variable a is written on addresses 0, 1, 2, 3, then variable b is written on addresses 4, 5, 6, 7 and then variable c is written on addresses 8, 9, 10, 11.

The next day at 11pm the values existing on the above addresses are replaced with new values on the same addresses. I don't want it to start from address 12 onwards.

Would you please let me know which is the correct answer to my situation?

If it makes any difference, I'm working on a Mega 2560 and I already have an RTC connected.

Thanks a lot

All of your reads are reading the same address. Can you show the particular readAnything and writeAnything code you have? I've seen different versions that different people have written. IF read also returns the number of bytes read then you can do the same trick of adding the returned value to the address like you did when you wrote them.

if the function EEPROM_writeAnything() suggests anything look to so what you want in a struct:

struct MyObject {
  float a, b, c;
};

MyObject myObject;
byte eeprom_address = 0;

void setup()
{
  EEPROM_readAnything(eeprom_address, myObject);
}

void loop()
{
  //likewise assign values to the object:
  myObject.a = 3.14;
  myObject.b = 8.34;
  myObject.c = 10.99;
  // and save the whole object
  EEPROM_writeAnything(eeprom_address, myObject);
}
void loop()
{
    void Write_EEPROM()
    {

I don't suppose it ever occurred to you to try compiling the code before you made yourself look stupid by posting it.

Asking if code that won't even compile will do what you want isn't going to get you good answers.

       if(hour() == 23)

Do you want to write the values to EEPROM once when hour() becomes 23 or every time through loop() whilst hour() is 23 ?