Save two-dimensional array into EEPROM memory

0

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

I thought of using an array, so the first element would be the reference for the specific object and the second the amount of brightness. I'm still new to programming in general, I researched, and I ended up thinking I was trying to use a two-dimensional array that did not work perfectly.

    
asked by anonymous 08.08.2014 / 16:33

1 answer

3

EEPROM has only two functions to read or write bytes . So you have to read / write your data byte to byte.

You can use something like this:

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 .

    
08.08.2014 / 18:09