LED shift array help

So, I am able to do this manually, and I will give my example of how I have achieved the result, but as in most cases there is sometimes a better and easier way to achieve the same result.

I am using shiftbrites first of all, and the base code I have received from Garrett at Macetech is as follows.

void NewKittFill(int dir, int FillSpeed, int FadeSteps, int red, int green, int blue) {
 
     for (int i = 0; i < NumLEDs; i++) {
       
       KittFadeFactor = ((KittFakeArray(KittTotalSize - FillCount + i)) * (FadeSteps - FadeCount - 1) + (KittFakeArray(KittTotalSize - FillCount - 1 + i)) * (FadeCount)) / (2 * FadeSteps);

      

         LEDChannels[i][0] = (long) red * KittFadeFactor / 1023; 
         LEDChannels[i][1] = (long) green * KittFadeFactor / 1023;
         LEDChannels[i][2] = (long) blue * KittFadeFactor / 1023;

So as most of you know this creates a fade among all the LEDs as defined in LEDChannels. What I was desiring was to have individual control of each shiftbrite as for the color. so if I wanted the first to be red, the second green, and the third blue I could control each one. the problem with the above code is that when I call NewKittFill, I only specify one RGB setting and it writes it to all LED’s.

This is where I have found a solution but a much harder one.

What I have done is the following:

void NewKittFill(int dir, int FillSpeed, int FadeSteps, int r1, int g1, int b1, int r2, int g2, int b2, int r3, int g3, int b3, int r4, int g4, int b4) {

 int KittFadeFactor = 0;
 int revIndex;
 
 
 for (int FillCount = 0; FillCount < (KittTotalSize+NumLEDs); FillCount++) {
 
   for (int FadeCount = 0; FadeCount < FadeSteps; FadeCount++) {
   
     for (int i = 0; i < NumLEDs; i++) {
       
       KittFadeFactor = ((KittFakeArray(KittTotalSize - FillCount + i)) * (FadeSteps - FadeCount - 1) + (KittFakeArray(KittTotalSize - FillCount - 1 + i)) * (FadeCount)) / (2 * FadeSteps);

       if (dir == 0) {

         LEDChannels[0][0] = (long) r1 * KittFadeFactor / 1023; 
         LEDChannels[0][1] = (long) g1 * KittFadeFactor / 1023;
         LEDChannels[0][2] = (long) b1 * KittFadeFactor / 1023;
         
         LEDChannels[1][0] = (long) r2 * KittFadeFactor / 1023; 
         LEDChannels[1][1] = (long) g2 * KittFadeFactor / 1023;
         LEDChannels[1][2] = (long) b2 * KittFadeFactor / 1023;
         
         LEDChannels[2][0] = (long) r3 * KittFadeFactor / 1023; 
         LEDChannels[2][1] = (long) g3 * KittFadeFactor / 1023;
         LEDChannels[2][2] = (long) b3 * KittFadeFactor / 1023;
         
         LEDChannels[3][0] = (long) r4 * KittFadeFactor / 1023; 
         LEDChannels[3][1] = (long) g4 * KittFadeFactor / 1023;
         LEDChannels[3][2] = (long) b4 * KittFadeFactor / 1023;

Then in my loop I call it as such:
NewKittFill(0,rate,8, 1023,0,0, 1023,100,0, 1023,200,0, 1023,400,0);

This is ok if I am using 1-10 LED’s but if I were to do this with anymore than ten LED’s it would probably drive me insane. Im sure there has to be a better way to do this, but I am not sure how. Can I make a function for each RGB LED and then somehow call each one in the NewKittFill function?

Im not looking for anyone to write anything for me, I would just like if someone could point me in the right direction.

Thank you for your time:
Jeremy

You should still have a decent amount of RAM left, I would go ahead and create another RGB array with the colors you want each LED to have. Then have the Kitt scan code access the desired colors in that array as it indexes through the channels, instead of using the colors passed to the function.

Thanks for the reply Mace,

I am confused as to what you mean though. I just posted a portion of what I had came up with, I wrote this which basically cycles from red all the way through the spectrum back to red in a continuous loop.

NewKittFill(0,rate,8, 1023,0,0, 1023,100,0, 1023,200,0, 1023,400,0);
   delay(200);
   NewKittFill(1,rate,8, 0,1023,0, 700,1023,0, 1023,800,0, 1023,400,0);
   delay(200);
   NewKittFill(0,rate,8, 0,1023,0, 0,1023,100, 0,1023,200, 0,1023,400);
   delay(200);
   NewKittFill(1,rate,8,  0,0,1023,  0,600,1023, 0,1023,800,  0,1023,400);
   delay(200);
   NewKittFill(0,rate,8,  0,0,1023,  0,0,1023, 0,0,1023, 0,0,1023);
   delay(200);
   NewKittFill(1,rate,8, 920,0,1023, 400,0,1023, 100,0,1023, 0,0,1023);
   delay(200);
   NewKittFill(0,rate,8, 920,0,1023, 920,0,900, 1023,0,700, 1023,0,500);
   delay(200);
   NewKittFill(1,rate,8, 1023,0,0,  1023,0,100, 1023,0,400,  1023,0,500);  
   delay(200);

This is working fine on 4 rows of LED's, but like I said if i incorporate more than ten I would have to have three integers per LED in the NewKitt function for a total of 33 integers to declare on every cycle.

I guess I am a little confused on your terminology, Ill keep experimenting and see if I can figure it out what I am trying to achieve

Look at the LEDChannels array, that gets dumped to the LEDs when you run WriteLEDArray. You could make another [n][3] array to store desired RGB values. Then in the Kitt function where it steps through each LED and writes the desired brightness * each channel, you would pull up the desired color for that LED instead of the global color used when calling the function.

Thanks again Mace,

I will try this out.

I have spent about 4 hours or so trying to figure this out with not much luck. Ill just manually have to code each line until i get better versed and can figure out what you mean.

I would really like some direction for doing this, I am having trouble understanding the concept of arrays and what you are pointing to do. I am able to make an array, but I cant figure out how I would call the colors out of it. I realize I am probably over my head here, But I am understanding the majority of the code above and what it does, but I just cant seem to grasp what you are hinting at.

It's going to be very difficult to give you enough information to do this yourself if we're starting with an explanation of an array. It's almost worse that you're trying to repurpose existing code to do things that are pretty different from the original intent of the code...it's possibly leading you in the wrong direction.

Can you describe, as precisely as possible, the color and fading effects you're trying to achieve? There may be shortcuts, and I'm willing to put new code together that's closer to your intended setup. It'll be fast to write if I have a clear idea what you need, and it'll be easier to modify if you need to do so.

Mace, Thanks again for responding!!!

Well I have done some reading, which I had did before but just couldnt grasp the concept of how to setup and call Arrays, I knew what they were but did not know how to implement them on my own. Anyways after going to numerous C++ sites I figured out somehow to use them. Basically what I am wanting to do is to be able to fade and array of LED’s like the night rider demo, but change their colors during a fade cycle, I was able to accomplish all of this using the night rider demo. But then I had the idea to be able to take any spot in the chain and fade outwards from that particular LED, so if I had a chain of 8 per say, starting on led 4 fade outwards to 1 and 8, and then back to center, This i could not figure out how to do using your code. I set up printpoints and wrote down all the integers for that code, and I can see the math, but I still can not figure out how you have it working, the LEDChannels are = to predetermined LED brightness * Kittfadefactor/1023. I would think that all channels would brighten the same since they are using the same formula. So I did the math on the revindex and it basically sets the unused channels in the array to the first 8, but i still cannot figure out what is going on. As in channel 15=0, 14=1, 13=2 and so on.

Anyways so last night I finally figured out how to implement arrays and call them, and I wrote this:

float ai[38] = {0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625,  .46875, .5, .625, .75, .8125,  .90625,  1,
                .9,.75,.5,.3,.25,.1,0,0,0,0,0,0,0,0,0,0,0,0};
float bi[38] = {0,0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625,  .46875, .5, .625, .75, .8125,  .90625,  1,
                1,.8,.75,.5,.4,.2,.1,0,0,0,0,0,0,0,0 };
float ci[38] = {0,0,0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625,  .46875, .5, .625, .75, .8125,  .90625,  1,
                .9,.75,.6,.4,.3,.25,.1,0,0,0,0,0,0,0,0,0};
float di[38] = {0,0,0,0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625, .4375,  .5, .625, .75, .8125,  .90625,  1,
                .9,.8,.75,.6,.5,.4,.3,.25,.1,0,0,0,0,0,0 };
float ei[38] = {0,0,0,0,0,0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625, .4375,  .5, .625, .75, .8125,  .90625,  1,
                .9,.75,.5,.3,.25,.1,0,0,0,0,0};
float fi[38] = {0,0,0,0,0,0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625, .4375,  .5, .625, .75, .8125,  .90625,  1,
                1,.8,.75,.5,.4,.2,.1,0,0,0,0 };
float gi[38] = {0,0,0,0,0,0,0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625, .4375,  .5, .625, .75, .8125,  .90625,  1,
                .9,.75,.6,.4,.3,.25,.1,0,0,0,0,0};
float hi[38] = {0,0,0,0,0,0,0,0, .03125, .0625, .09375, .125, .15625, .1875, .21875, .25, .28125, .3125,
                .375, .40625, .4375, .5, .625, .75, .8125,  .90625,  1,
                .9,.8,.75,.6,.5,.4,.3,.25,.1,0,0 };




// Fade between two colors at specified interval
void fadeall(int rate, int fromred, int fromgreen, int fromblue) {
int x=1;
 for (int i = 0; i <40;i++) {
      //if (i == 32) x = -1;
     
   
  // for (int i = 0; i > -1; i = i + x){
      
    //  if (i = 33) x = -1;             // switch direction at peak
      
     for (int j1 = 0; j1 < NumLEDs; j1++) {
       LEDChannels[7][0] = fromred * ai[i];
       LEDChannels[7][1] = fromgreen * ai[i];
       LEDChannels[7][2] = fromblue * ai[i];
         
         LEDChannels[6][0] = fromred * bi[i];
       LEDChannels[6][1] = fromgreen * bi[i];
       LEDChannels[6][2] = fromblue * bi[i];
         
         LEDChannels[5][0] = fromred * ci[i];
       LEDChannels[5][1] = fromgreen * ci[i];
       LEDChannels[5][2] = fromblue * ci[i];
     
         LEDChannels[4][0] = fromred * di[i];
       LEDChannels[4][1] = fromgreen * di[i];
       LEDChannels[4][2] = fromblue * di[i];
        
         LEDChannels[3][0] = fromred * ei[i];
       LEDChannels[3][1] = fromgreen * ei[i];
       LEDChannels[3][2] = fromblue * ei[i];
         
         LEDChannels[2][0] = fromred * fi[i];
       LEDChannels[2][1] = fromgreen * fi[i];
       LEDChannels[2][2] = fromblue * fi[i];
         
         LEDChannels[1][0] = fromred * gi[i];
       LEDChannels[1][1] = fromgreen * gi[i];
       LEDChannels[1][2] = fromblue * gi[i];
     
         LEDChannels[0][0] = fromred * hi[i];
       LEDChannels[0][1] = fromgreen * hi[i];
       LEDChannels[0][2] = fromblue * hi[i];
     
     }
    WriteLEDArray();
    delay(75);
     
   }
}

void loop() {
  
  fadeall(600,1023,0,0);
  delay(1);
  fadeall(600,0,1023,0);
  delay(1);
  fadeall(10,0,0,1023);

I can move the ai,bi,ci’…'s around anywhere in the led array i want to control the starting point and direction of the fades, as well as how fast by adjusting the ai,bi array multiplier integers. Im sure this is not the easy way to do it, but its a starting point for a newb like me. If you have any suggestions id love to hear how to make this easier on me, but once again im not asking you to write me anything, I will learn more just taking hints than copying your code. Hopefully I can get signed up in the spring to take a C programming course at the local college, Im sure it would benefit me immensely.