Reef LED controller

First of all, I am new to arduino and the c++ language, I have self taught myself the basics of the language by reading through various different sketches and attempting to understand these. So in advance I must apologise for any glaring mistakes I may be making or any ignorance in my replies!

I have been attempting to modify a piece of code called ‘stilo 2.1’ to control six led channels, rather than just two. The leds are involved in a lighting system above a fish tank and are dimmed to create different colour temperatures and effects for dawn and dusk, and provide sufficient light during the day to keep the corals happy.

I have successfully managed to increase the number of channels and all work fine bar one problem I have been having. When adjusting the led dimming on the unit, I can’t get the values for the added channels to save to the eeprom, in the event of a powercut and reboot, they revert to their original levels.

I am using the writeAnything.h code to write to/read from the eeprom. This is all being done on a mega 1280.

The original ‘stilo 2.1’ code:

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);
  char tempString[3];
  
  if (k==123) {
    for (int i=1; i<97; i++)  {
      wled[i] = EEPROM.read(i);
      bled[i] = EEPROM.read(i+96);
    }  
   }
}

My additions:

void SaveLEDToEEPROM()
{
  EEPROM.write(0, tled[96]);
  for (int i=0; i<=95; i++) { 
    EEPROM.write(i, wled[i]);
    EEPROM.write(i+96, bled[i]);
    EEPROM.write(i+192, rled[i]);
    EEPROM.write(i+288, uled[i]);
    EEPROM.write(i+384, yled[i]);
    EEPROM.write(i+480, gled[i]);
  }
}
  
void ReadFromEEPROMwb()
{
  int k = EEPROM.read(0);
  char tempString[3];
  
  if (k==tled[96]) {
    for (int i=0; i<=95; i++) { 
      wled[i] = EEPROM.read(i);
      bled[i] = EEPROM.read(i+96);
      rled[i] = EEPROM.read(i+192);
      uled[i] = EEPROM.read(i+288);
      yled[i] = EEPROM.read(i+384);
      gled[i] = EEPROM.read(i+480);
    }
  }
}

I have tried countless different combinations over the past few months but just can’t crack it! Any help would be greatly appreciated and if you need any further information, don’t hesistate to ask.

Thanks in advance.

I have tried countless different combinations over the past few months but just can't crack it! Any help would be greatly appreciated and if you need any further information, don't hesistate to ask.

OK. I'm asking. That code does something. You want it do something else. What are those two somethings?

I have been attempting to modify a piece of code called 'stilo 2.1' to control six led channels, rather than just two.

The code in question allows the led values to be changed via the touchscreen and those values to be saved to the eeprom so in the event of a power outage, all the data is stored. So I am expanding the original code from two channels, to six.

So I am expanding the original code from two channels, to six.

Well, great. Glad that it's all working for you.

If it isn't, you really need to tell us what isn't doing what you want, and what it is that you want it to do.

As per my original post:

I have successfully managed to increase the number of channels and all work fine bar one problem I have been having. When adjusting the led dimming on the unit, I can't get the values for the added channels to save to the eeprom, in the event of a powercut and reboot, they revert to their original levels.

I was wondering if there is an error in the eepromread/write code I have written and am seeking advice to resolve it.

I was wondering if there is an error in the eepromread/write code I have written and am seeking advice to resolve it.

Without seeing how the arrays are declared, it's hard to be certain. But, since you are referencing the 96 elements in wLed, bLen, etc. I assume that tLed is the same size. If that is the case, it has no tLed[96] entry.

But, even if it does, you are writing that value in address 0, then stepping on that value with wLed[0].

You might notice that in the original code, the loop starts with i=1, writes the values from wLed[1] through wLed[96] to EEPROM. In other words, the code you started from was crap.