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)