Save bi-dimensional array to EEPROM memory

Asked

Viewed 368 times

0

I’m making a program for the Arduino written in C++ to turn on and off leds when a button is pressed. I want to save in an EEPROM memory the values of the leds that are connected and the amount of luminosity.

I thought to use an array, so the first element would be the reference for the specific object and the second amount of luminosity. I’m still new to programming in general, I did a little research and I ended up trying to use a bi-dimensional array, which ended up not working perfectly.

  • 2

    Your question does not contain a question XD Be more specific. And it is always good to put what you have already done.

1 answer

3

The EEPROM has only two functions to read or write bytes. Then you must necessarily read/write your data byte by byte.

You can wear something like that:

void EEPROM_writeMany(unsigned addressOffset, char* array, unsigned size) {
    for (int i = 0; i < size; ++i)
        EEPROM.write(addressOffset+i, array[i]);
}

int data[] = {54, 87, 21, -5, 0};

EEPROM_writeMany(0, (char*)data, sizeof(data));

To read, simply create an analog function using EEPROM.read.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.