Here is a simple sketch which writes multiple integer arrays to EEPROM. The write and read functions write/read to an address and an address +1. The number of EEPROM addresses required for an array will be 2x the size of the array.
Please pay attention to the computation of the EEPROM address from the array number and element.
An array element's EEPROM address is 2the array element _+ 2 the number of elements in the array*the array number[j] + Offset._
Array numbers and elements start at 0.
```
*#include <EEPROM.h>
int my2dArray[2][8] =
{
{0x8888, 0x9999, 0xAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEE, 0xFFFF},
{0x9999, 0xAAAA, 0xBBBB, 0xCCCC, 0xDDDD, 0xEEEE, 0xFFFF, 0x8888}
};
void setup(){
Serial.begin(9600);
int address;
Serial.println ("Writing data.....");
for(int j=0; j<2; j++){
Serial.println();
for(int i=0; i<8; i++){
EEPROMWriteInt(address= ((2i)+(j16)+50), my2dArray[j][i]);//+50 to not start at 0
Serial.println(address);
}
}
Serial.println();
Serial.println();
Serial.println ("Reading data.....");
for(int j=0; j<2; j++){
Serial.println();
for(int i=0; i<8; i++){
unsigned int value= EEPROMReadInt(address=(2i)+(j16)+50);//+50 to not start at 0
Serial.print(address);
Serial.print('\t');
Serial.println(value,HEX);
}
}
}
void loop(){
}
//integer read/write functions found at http://forum.arduino.cc/index.php/topic,37470.0.html
//This function will write a 2 byte integer to the eeprom at the specified address and address + 1
void EEPROMWriteInt(int p_address, int p_value)
{
byte lowByte = ((p_value >> 0) & 0xFF);
byte highByte = ((p_value >> 8) & 0xFF);
EEPROM.write(p_address, lowByte);
EEPROM.write(p_address + 1, highByte);
}
//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
unsigned int EEPROMReadInt(int p_address)
{
byte lowByte = EEPROM.read(p_address);
byte highByte = EEPROM.read(p_address + 1);
return ((lowByte << 0) & 0xFF) + ((highByte << 8)& 0xFF00);
}*
```