EEPROM Question

I am currently a TFT LED Controller with 2 LED channels. These LED channels have 96 different variables that are stored in the EEPROM in case of a power outage. I’m running a Mega1280 btw. So i’m looking to add 2 more LED channels but the variables won’t store in the EEPROM…please help…here is part of the coding:

//Dimming vales can be changed below
//Dimming values 8am_to_10pm_2hrDawn_2hrDusk_moonlight_75percent  
byte bled[96] = {
  26, 26, 26, 26, 26, 26, 26, 26,  		//23:46-00:01-00:16-00:31-00:46-01:01-01:16-01:31
  26, 26, 26, 26, 26, 26, 26, 26,  		//01:46-02:01-02:16-02:31-02:46-03:01-03:16-03:31
  26, 26, 26, 26, 26, 26, 26, 26,  		//03:46-04:01-04:16-04:31-04:46-05:01-05:16-05:31
  26, 32, 64, 96, 128, 160, 192, 224,  		//05:46-06:01-06:16-06:31-06:46-07:01-07:16-07:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//07:46-08:01-08:16-08:31-08:46-09:01-09:16-09:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//09:46-10:01-10:16-10:31-10:46-11:01-11:16-11:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//11:46-12:01-12:16-12:31-12:46-13:01-13:16-13:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//13:46-14:01-14:16-14:31-14:46-15:01-15:16-15:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//15:46-16:01-16:16-16:31-16:46-17:01-17:16-17:31
  255, 255, 255, 255, 255, 255, 224, 192,  	//17:46-18:01-18:16-18:31-18:46-19:01-19:16-19:31
  160, 128, 96, 64, 32, 26, 26, 26,  	        //19:46-20:01-20:16-20:31-20:46-21:01-21:16-21:31
  26, 26, 26, 26, 26, 26, 26, 26   		//21:46-22:01-22:16-22:31-22:46-23:01-23:16-23:31
};  
byte wled[96] = {
  0, 0, 0, 0, 0, 0, 0, 0,                  //23:46-00:01-00:16-00:31-00:46-01:01-01:16-01:31
  0, 0, 0, 0, 0, 0, 0, 0,                  //01:46-02:01-02:16-02:31-02:46-03:01-03:16-03:31
  0, 0, 0, 0, 0, 0, 0, 0,                  //03:46-04:01-04:16-04:31-04:46-05:01-05:16-05:31
  0, 16, 32, 48, 64, 80, 96, 112,          //05:46-06:01-06:16-06:31-06:46-07:01-07:16-07:31
  128, 144, 160, 176, 192, 208, 224, 240,  //07:46-08:01-08:16-08:31-08:46-09:01-09:16-09:31
  255, 255, 255, 255, 255, 255, 255, 255,  //09:46-10:01-10:16-10:31-10:46-11:01-11:16-11:31
  255, 255, 255, 255, 255, 255, 255, 255,  //11:46-12:01-12:16-12:31-12:46-13:01-13:16-13:31
  255, 255, 255, 255, 255, 255, 255, 255,  //13:46-14:01-14:16-14:31-14:46-15:01-15:16-15:31
  255, 240, 224, 208, 192, 176, 160, 144,  //15:46-16:01-16:16-16:31-16:46-17:01-17:16-17:31
  128, 112, 96, 80, 64, 48, 32, 16,        //17:46-18:01-18:16-18:31-18:46-19:01-19:16-19:31
  0, 0, 0, 0, 0, 0, 0, 0,                  //19:46-20:01-20:16-20:31-20:46-21:01-21:16-21:31
  0, 0, 0, 0, 0, 0, 0, 0                   //21:46-22:01-22:16-22:31-22:46-23:01-23:16-23:31
};  //White LED array in RAM
byte rbled[96] = {
  26, 26, 26, 26, 26, 26, 26, 26,  		//23:46-00:01-00:16-00:31-00:46-01:01-01:16-01:31
  26, 26, 26, 26, 26, 26, 26, 26,  		//01:46-02:01-02:16-02:31-02:46-03:01-03:16-03:31
  26, 26, 26, 26, 26, 26, 26, 26,  		//03:46-04:01-04:16-04:31-04:46-05:01-05:16-05:31
  26, 32, 64, 96, 128, 160, 192, 224,  		//05:46-06:01-06:16-06:31-06:46-07:01-07:16-07:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//07:46-08:01-08:16-08:31-08:46-09:01-09:16-09:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//09:46-10:01-10:16-10:31-10:46-11:01-11:16-11:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//11:46-12:01-12:16-12:31-12:46-13:01-13:16-13:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//13:46-14:01-14:16-14:31-14:46-15:01-15:16-15:31
  255, 255, 255, 255, 255, 255, 255, 255,  	//15:46-16:01-16:16-16:31-16:46-17:01-17:16-17:31
  255, 255, 255, 255, 255, 255, 224, 192,  	//17:46-18:01-18:16-18:31-18:46-19:01-19:16-19:31
  160, 128, 96, 64, 32, 26, 26, 26,  	        //19:46-20:01-20:16-20:31-20:46-21:01-21:16-21:31
  26, 26, 26, 26, 26, 26, 26, 26   		//21:46-22:01-22:16-22:31-22:46-23:01-23:16-23:31
};  
byte rled[96] = {
  0, 0, 0, 0, 0, 0, 0, 0,                  //0 - 1
  0, 0, 0, 0, 0, 0, 0, 0,                  //2 - 3
  0, 0, 0, 0, 0, 0, 0, 0,                  //4 - 5
  0, 0, 0, 0, 0, 0, 0, 0,                  //6 - 7
  0, 0, 0, 0, 0, 0, 0, 0,                  //8 - 9
  0, 28, 32, 55, 80, 100, 100, 100,        //10 - 11
  100, 100, 100, 100, 100, 100, 100, 100,  //12 - 13
  100, 100, 100, 100, 100, 100, 100, 100,  //14 - 15
  100, 100, 100, 100, 100, 100, 100, 100,  //16 - 17
  100, 100, 100, 100, 100, 100, 100, 100,  //18 - 19
  90, 70, 50, 30, 0, 0, 0, 0,              //20 - 21
  0, 0, 0, 0, 0, 0, 0, 0    
};  

byte tled[96];        //temporary array to hold changed led values
void SaveLEDToEEPROM()
{
  EEPROM.write(0, 384);         //to determine if data available in EEPROM
  for (int i=1; i<97; i++)  {
    EEPROM.write(i, wled[i]);
    EEPROM.write(i+96, bled[i]);
    EEPROM.write(i+192, rbled[i]);
    EEPROM.write(i+288, rled[i]);
  } 
}
void ReadFromEEPROM()
{
  int k = EEPROM.read(0);
  
  if (k==384) {
    for (int i=1; i<97; i++)  {
      wled[i] = EEPROM.read(i);
      bled[i] = EEPROM.read(i+96);
      rbled[i] = EEPROM.read(i+192);
      rled[i] = EEPROM.read(i+288);
    }  
   }

Why aren’t the values being written and read? Am I missing something?

Why are you storing hard-coded values in EEPROM?

  EEPROM.write(0, 384);         //to determine if data available in EEPROM

Writing to EEPROM doesn’t determine anything.

  for (int i=1; i<97; i++)  {

Array indices start at 0.

Why aren’t the values being written and read?

How do you know that they aren’t?

The hard coded values can actually be changed within the TFT menu system. So i=1 would be i=0? And i've changed the "default" hard-coded values and saved hem to the eeprom but after unplugging it and plugging it back in the default values come back. Do I need to comment these values out?

So i=1 would be i=0?

Yes or no. You are writing to addresses 1, 2, 3, etc. the values in wled[0], wled[1], wled[2], etc.

You can't use the same value for the address and the index.

Do I need to comment these values out?

Where are you calling the function to read the values from EEPROM?

Hmmm.....it perplexes me with the addition of two other lighting channels.....because just the original 2 channels will store the values when changed in the menu system and unplugged and plugged back in.... am using the Stilo 2.1 sketch as a base for this design which can be found here.

Where is the EEPROM you are writing to? On the Arduino or on the touch screen? How big is the EEPROM?

am using the eeprom on the mega

That EEPROM is larger than 384 bytes, so, likely the problem is the loop index being used as the array index and address, incorrectly.

Hmmm…here is the original eeprom save and read code PaulS.The only thing I really did was change the values to double the original to include the 2 new lighing channels and for a temperature variable also…so do I need to change the 123 to 246 for the 2 added channels with 96 values?

void SaveLEDToEEPROM()
{
  EEPROM.write(0, 123);         //to determine if data available in EEPROM
  for (int i=1; i<97; i++)  {
    EEPROM.write(i, wled[i]);
    EEPROM.write(i+96, bled[i]);
  } 
}
 
//---------------------------------------------------------------------------------------------

void ReadFromEEPROM()
{
  int k = EEPROM.read(0);

  
  if (k==123) {
    for (int i=1; i<97; i++)  {
      wled[i] = EEPROM.read(i);
      bled[i] = EEPROM.read(i+96);
    }  
   }

here is the original eeprom save and read code

That's rubbish, too.

In your code, write out the value you read from address 0. If that is bad, none of the reads will take place. At least we will then have a clue.

This was pointed out but you seemed to ignore it.

Your array is 96 elements wide:

byte bled[96] = {

This means the index of the first element is 0 and the last element is 95.

Then you write to EEPROM using this loop:

for (int i=1; i<97; i++)  {

So the last value i will be is 96. The last element is 95. wled[96] is going to be undefined.

sorry James...am at a lose....lol....been 10yrs since I last used C++.....the original sketch came from someone else but it works with their version....I just want to add two more "channels" and get it to work.

I just want to add two more "channels" and get it to work.

You can't just "add two more channels" to crappy code, no matter where you got it, and "get it to work".

You MUST use different values for the array index and the address offset. Here's a hint. The values differ, always, by EXACTLY one. So, you can use the same variable, but you must subtract or add 1 to the value, for either the address or the index.