Motion in LED strip "zones" problems, keeping track of many variables, et all

I have been troubleshooting some code that i can't get to work, and i know why it isn't working. The problem is that I am redefining variables that I have to keep separate. I could make a thousand different variables if sram wasn't an issue, but i'm feeling I am just doing something wrong.

What i want to be able to is:

I have four zones of LED light strips, and for each of those zones, i plan to write 20 or so different functions or programs that each zone of the led strip can run.

SO i need to keep track of how long each zone is, and what program is running on the zone.

this function was supposed to do that (but it seems like it only works some times)

void LEDshow() { 
  if (ledAction[led1Action] == 1) { //if zone 1 is on, then
    pixelStart = 0;  
    pixelEnd = LastZone1Pixel; //the length of the zone is defined here
    functionsArray [zone1Function] ();  //the program is chosen using an array, where functions array is an array of function names, and zone1Function is an integer.  This works. I think.
  }
  if (ledAction[led2Action] == 1) {
    pixelStart = LastZone1Pixel;  //but it seems like if i have two zones on, pixelStart will be redefined?  
    pixelEnd = LastZone2Pixel;
    functionsArray [zone2Function] ();
  } 
  if (ledAction[led3Action] == 1) {
    pixelStart = LastZone2Pixel;
    pixelEnd = LastZone3Pixel;
    functionsArray [zone3Function] ();
  }
  if (ledAction[led4Action] == 1) {
    pixelStart = LastZone3Pixel;
    pixelEnd = LastZone4Pixel;
    functionsArray [zone4Function] ();
  }    
}

I think that it should be OK if pixelStart is redefined, since before I moved on to the next "if Statement" that zone's function should have executed and changed the LEDarray.

The code works perfectly for STATIC non changing lightshows, but if i try to add a chasing or fade affect, the lights don't change as expected.

here are two example "functions" that the ledShow function can call.

void green(){
  for(int i = pixelStart; i < pixelEnd; i++) {
    leds[i].r = 0; 
    leds[i].g = 255; 
    leds[i].b = 0;
  }
}

that works....

void chasing() {
   for(int i = pixelEnd-1; i > pixelStart; i-- ) {
      leds[i].r = leds[i-1].r;
      leds[i].g = leds[i-1].g;
      leds[i].b = leds[i-1].b;
  }
  // Fade out the color.  After 8 steps the color should be completely gone.
  leds[pixelStart].r /= 2;
  leds[pixelStart].g /= 2;
  leds[pixelStart].b /= 2;
}

something like this, doesn't work. The lights chase, but only once, too fast, and if i have more than one zone selected, they don't seem to keep track of what zone they are in very well.

I've also attached my code.

_6803_LED_box1.ino (16.3 KB)

Sorry you lost me right at the beginning of your code

if (ledAction[led1Action]

So is ledAction an array of things or is it an integer that you use to point into the array?

ledAction[led1Action]

is used to keep track of whether or not a zone is "active". If it is equal to one, it is active, if it is equal to zero it isn't active.

led action is an array of 4 numbers that represent 4 zones, each of which can hold the value of 1, 2, 3 or 4 to describe the current state of the zone. If it is zero, the zone is off, if it is one, the zone is on, if it is 2 or 3, the zone is being set up.

led1Action is defined as the first number of the ledAction array.

Thanks for your response!

it would be helpful to see how you are initializing the arrays... can you post your whole sketch?

I did, Its attached in the OP.

I attached it here again, in case I uploaded the wrong one.

_6803_LED_box1.ino (16.3 KB)

AH. Sorry it's getting late, my eyes are bleary, and I didn't notice that 1 in the middle of Led1Action :slight_smile:

one problem was a simple math problem, the color was going to zero and wasnt getting refreshed. I fixed that issue, and now the lights chase, but I am just thinking there might be a better way....

also, they are still a lot faster than I'd like them to be, so I'd have to create timers for every function to slow it down....

  if (ledAction[led1Action] == 1) { //if zone 1 is on, then

Why the hell not use names that make sense? There appears to be no relationship between the name of the array and zones, and there appears to be no relationship between led1action and the value 1.

That code might as well read:
if(smith[wesson] == 45)
for all the meaning that is to be gleaned from the names.

I have been troubleshooting some code that i can't get to work, and i know why it isn't working. The problem is that I am redefining variables that I have to keep separate. I could make a thousand different variables if sram wasn't an issue, but i'm feeling I am just doing something wrong.

Well, you are the only one with the cheat sheet that defines what all those silly names mean, so if you can't keep them straight, you can't expect anyone else to.