How do I put two different type of objects in EEPROM

How do I put two different type of objects in EEPROM

class Schedule{
    public:
        float hour;
        bool isFlashWindow;
        bool sendHeartBeat;
};

I have two objects

  1. Schedule schedules[5]
  2. Schedule curSchedule

how do I put and retrieve these objects in EEPROM?

is this correct way??

//saving
EEPROM.put(1, schedules);
EEPROM.put(6, nextSchedule);

//retrieving
EEPROM.get(1, schedules);
EEPROM.get(6, nextSchedule);

Have you tried it?
I seem to remember suggesting something other than “guessing” the size of an object and using hardcoded numbers in another thread about EEPROM :wink:

Previously for float array

I had used

sizeof(float)*1

now for schedules array and schedule object what should be used?

So when you used sizeof(float) for float variables, what would one obviously use when looking at an object of “type” Schedule?

BTW, how did you come up with an offset of 5 for your hardcoded version?
One float plus two bool variables does not account for 5 bytes.

how did you come up with an offset of 5

thats where I am stuck, length of array is 5 that is why I have hardcoded 5 there (I guess that is incorrect)

No, 5 is the number of items you store in that array. The length of the array is 5 times the length of each individual item.

so what I should use instead of this? can you please provide details

I think I have provided all details required to find the solution.
You need to put the information provided together to understand what you are doing.

I could provide the ready-meal solution for this problem (as I did for the one before) but without you understanding why and how to apply that on any new "problem" in the same direction you'd need to ask for yet another spoonfeeding next time.

I'll reiterate one key-question I raised above - the answer to that will provide the full solution

struct Schedule{
    public:
        float hour;
        bool isFlashWindow;
        bool sendHeartBeat;
};
/*
    Schedule schedules[5]
    Schedule curSchedule
*/
EEPROM.put(8, curSchedule);
EEPROM.put(40, schedules);

this seems correct

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.