TLC5940 Rainbow Fade question

Hello!

So I’d promised I’d help a fellow member with some TLC5940 Rainbow code and I’m having a little bit of trouble.
For some reason nothing gets output on the LEDs, at all. The code seems fine but I don’t get why it won’t come on.

I’m using 15 RGB Leds with 3 TLC5940’s and I don’t have the channel 0 connected on any of their respective TLC5940’s
You can also see that I have each TLC5940 separated by color.
I already have the values for the colors in, its just making it fade.

/* 
    Rainbow fader using 3 TLC5940 along with 15 common anode RGB LEDs
    By Shannon Strutz
    8/15/2012
    funkyguy4000.wordpress.com
*/

#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;

//Defining RGB Color pins.  Notice I have each color on their own TLC5940
int BluePins[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
int GreenPins[] = {18,19,20,21,22,23,24,25,26,27,28,29,30,31,32};
int RedPins[] = {34,35,36,37,38,39,40,41,42,43,44,45,46,47,48};

//Defining colors.  Rainbow goes Red->Orange->Yellow->Green->Blue->Indigo->Violet->Repeat
int RRed = 255;
int BRed = 0;
int GRed = 0;
int Red[] = {RRed, BRed, GRed};

int ROrange = 255;
int BOrange = 127;
int GOrange = 0;
int Orange[] = {ROrange, BOrange, GOrange};

int RYellow = 255;
int BYellow = 255;
int GYellow = 0;
int Yellow[] = {RYellow, BYellow, GYellow};

int RGreen = 0;
int BGreen = 0;
int GGreen = 255;
int Green[] = {RGreen, BGreen, GGreen};

int RBlue = 0;
int BBlue = 255;
int GBlue = 0;
int Blue[] = {RBlue, BBlue, GBlue};

int RIndigo = 75;
int BIndigo = 130;
int GIndigo = 0;
int Indigo[] = {RIndigo, BIndigo, GIndigo};

int RViolet = 143;
int BViolet = 255;
int GViolet = 0;
int Violet[] = {RViolet, BViolet, GViolet};

int RedRainbow[] = {Red[0], Orange[0], Yellow[0], Green[0], Blue[0], Indigo[0], Violet[0]};
int BlueRainbow[] = {Red[1], Orange[1], Yellow[1], Green[1], Blue[1], Indigo[1], Violet[1]};
int GreenRainbow[] = {Red[2], Orange[2], Yellow[2], Green[2], Blue[2], Indigo[2], Violet[2]};
//int Rainbow[] = {RedRainbow[], BlueRainbow[], GreenRainbow[]};



void setup()
{
  Tlc.init();
}

void loop()
{
      uint16_t duration = 200;
        for (int r = 0; r<17 ; r++)
        {
          uint32_t startMillisr = r*10;
          uint32_t endMillisr = startMillisr + duration;
          tlc_addFade(RedPins[r], Red[0], Orange[0], startMillisr, endMillisr);
          tlc_addFade(RedPins[r], Orange[0], Yellow[0], startMillisr, endMillisr);
          tlc_addFade(RedPins[r], Yellow[0], Green[0], startMillisr, endMillisr);
          tlc_addFade(RedPins[r], Green[0], Blue[0], startMillisr, endMillisr);
          tlc_addFade(RedPins[r], Blue[0], Indigo[0], startMillisr, endMillisr);
          tlc_addFade(RedPins[r], Indigo[0], Violet[0], startMillisr, endMillisr);
          tlc_addFade(RedPins[r], Violet[0], Red[0], startMillisr, endMillisr);
          if (r == 16)
          {
            r = 0;
          }
        }
                
        for (int g = 0; g<16; g++)
        {
          uint32_t startMillisg = g*10;
          uint32_t endMillisg = startMillisg + duration;
          tlc_addFade(GreenPins[g], Red[1], Orange[1], startMillisg, endMillisg);
          tlc_addFade(GreenPins[g], Orange[1], Yellow[1], startMillisg, endMillisg);
          tlc_addFade(GreenPins[g], Yellow[1], Green[1], startMillisg, endMillisg);
          tlc_addFade(GreenPins[g], Green[1], Blue[1], startMillisg, endMillisg);
          tlc_addFade(GreenPins[g], Blue[1], Indigo[1], startMillisg, endMillisg);
          tlc_addFade(GreenPins[g], Indigo[1], Violet[1], startMillisg, endMillisg);
          tlc_addFade(GreenPins[g], Violet[1], Red[1], startMillisg, endMillisg);
        }
        
        for (int b = 0; b<16; b++)
        {
          uint32_t startMillisb = b*10;
          uint32_t endMillisb = startMillisb + duration;
          tlc_addFade(BluePins[b], Red[2], Orange[2], startMillisb, endMillisb);
          tlc_addFade(BluePins[b], Orange[2], Yellow[2], startMillisb, endMillisb);
          tlc_addFade(BluePins[b], Yellow[2], Green[2], startMillisb, endMillisb);
          tlc_addFade(BluePins[b], Green[2], Blue[2], startMillisb, endMillisb);
          tlc_addFade(BluePins[b], Blue[2], Indigo[2], startMillisb, endMillisb);
          tlc_addFade(BluePins[b], Indigo[2], Violet[2], startMillisb, endMillisb);
          tlc_addFade(BluePins[b], Violet[2], Red[2], startMillisb, endMillisb);
        }
  
  
tlc_updateFades();
}

You're changing the loop variable inside the loop. So your first for() loop never exists.

also, I don't see any reason to set the same pin's fade value 7 times. It's going to take whatever they last setting was before you call the update.

I don't quite follow with the variable dealio.

I'm setting them 7 times because thats what they need for the rainbow. Should I call the update method after each one?

In your first for() loop. You keep resetting r to 0. The loop will never finish.

I don't know how to tell you to fix the fade logic. If you want a certain LED to fade a certain amount, you can't give it 7 different values with the same start and end time. Only the last one will do anything.

OHHH!!! wow, I though I removed that R reset.

and the time values wow. Thanks, I'll switch it up and let you know how it goes.

mmkay so I changed it to this:

void loop()
{
        for (int r = 0; r<17 ; r++)
        {
          uint32_t startMillisr = r*10;
          tlc_addFade(RedPins[r], Red[0], Orange[0], startMillisr, startMillisr + 100);
          tlc_addFade(RedPins[r], Orange[0], Yellow[0], startMillisr +100, startMillisr+200);
          tlc_addFade(RedPins[r], Yellow[0], Green[0], startMillisr+200, startMillisr+300);
          tlc_addFade(RedPins[r], Green[0], Blue[0], startMillisr+300, startMillisr+400);
          tlc_addFade(RedPins[r], Blue[0], Indigo[0], startMillisr+400, startMillisr+500);
          tlc_addFade(RedPins[r], Indigo[0], Violet[0], startMillisr+500, startMillisr+600);
          tlc_addFade(RedPins[r], Violet[0], Red[0], startMillisr+600, startMillisr+700);
        }
                
        for (int g = 0; g<17; g++)
        {
          uint32_t startMillisg = g*10;
          tlc_addFade(GreenPins[g], Red[1], Orange[1], startMillisg, startMillisg+100);
          tlc_addFade(GreenPins[g], Orange[1], Yellow[1], startMillisg+100, startMillisg+200);
          tlc_addFade(GreenPins[g], Yellow[1], Green[1], startMillisg+200, startMillisg+300);
          tlc_addFade(GreenPins[g], Green[1], Blue[1], startMillisg+300, startMillisg+400);
          tlc_addFade(GreenPins[g], Blue[1], Indigo[1], startMillisg+400, startMillisg+500);
          tlc_addFade(GreenPins[g], Indigo[1], Violet[1], startMillisg+500, startMillisg+600);
          tlc_addFade(GreenPins[g], Violet[1], Red[1], startMillisg+600, startMillisg+700);
        }
        
        for (int b = 0; b<17; b++)
        {
          uint32_t startMillisb = b*10;
          tlc_addFade(BluePins[b], Red[2], Orange[2], startMillisb, startMillisb+100);
          tlc_addFade(BluePins[b], Orange[2], Yellow[2], startMillisb+100, startMillisb+200);
          tlc_addFade(BluePins[b], Yellow[2], Green[2], startMillisb+200, startMillisb+300);
          tlc_addFade(BluePins[b], Green[2], Blue[2], startMillisb+300, startMillisb+400);
          tlc_addFade(BluePins[b], Blue[2], Indigo[2], startMillisb+400, startMillisb+500);
          tlc_addFade(BluePins[b], Indigo[2], Violet[2], startMillisb+500, startMillisb+600);
          tlc_addFade(BluePins[b], Violet[2], Red[2], startMillisb+600, startMillisb+700);
        }
   tlc_updateFades();
}

Which outputs this:

You cant call fade() on the same pin with the same start and stop time. ONLY THE LAST ONE before the update takes effect.

Hmmmmm, I think I'll be doing some hard coding. I forgot to convert the sRGB values to the values the tlc5940 reads that go from 0 - 4096.

Holy crap this is getting frustrating. The issue I'm having the most is the fact that I need to hold the red led at a value sometimes after the fade is done. Throwing in another tlc_addFade( #RedPin#, maxValue, maxValue, startMillis, endMIllis); doesn't work, for some reason it resets the fade and goes from 0 to maxValue instead.

I'm still at the point where I was in my previous update

bump?

Replace your loop() with this code, I would expect your sequence will look the same.

void loop()
{
        for (int r = 0; r<17 ; r++)
        {
          uint32_t startMillisr = r*10;
          tlc_addFade(RedPins[r], Violet[0], Red[0], startMillisr+600, startMillisr+700);
        }
                
        for (int g = 0; g<17; g++)
        {
          uint32_t startMillisg = g*10;
          tlc_addFade(GreenPins[g], Violet[1], Red[1], startMillisg+600, startMillisg+700);
        }
        
        for (int b = 0; b<17; b++)
        {
          uint32_t startMillisb = b*10;
          tlc_addFade(BluePins[b], Violet[2], Red[2], startMillisb+600, startMillisb+700);
        }
   tlc_updateFades();
}

will that only fade from violet to red?

Try it and see what happens.

Okay so here is the full code now of what i’m using, note I did change the pin layout. Instead of having each color on their own tlc, I have them going red green blue, red green blue, and so on:

#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;

//Defining RGB Color pins.  Notice I have each color on their own TLC5940
int RedPins[] = {1,4,7,10,13,17,20,23,26,29,33,36,39,42,45};
int GreenPins[] = {2,5,8,11,14,18,21,24,27,30,34,37,40,43,46};
int BluePins[] = {3,6,9,12,15,19,22,25,28,31,35,38,41,44};

//Defining colors.  Rainbow goes Red->Orange->Yellow->Green->Blue->Indigo->Violet->Repeat
int RRed = 255;
int BRed = 0;
int GRed = 0;
int Red[] = {RRed, BRed, GRed};

int ROrange = 255;
int BOrange = 127;
int GOrange = 0;
int Orange[] = {ROrange, BOrange, GOrange};

int RYellow = 255;
int BYellow = 255;
int GYellow = 0;
int Yellow[] = {RYellow, BYellow, GYellow};

int RGreen = 0;
int BGreen = 0;
int GGreen = 255;
int Green[] = {RGreen, BGreen, GGreen};

int RBlue = 0;
int BBlue = 255;
int GBlue = 0;
int Blue[] = {RBlue, BBlue, GBlue};

int RIndigo = 75;
int BIndigo = 130;
int GIndigo = 0;
int Indigo[] = {RIndigo, BIndigo, GIndigo};

int RViolet = 143;
int BViolet = 255;
int GViolet = 0;
int Violet[] = {RViolet, BViolet, GViolet};

int RedRainbow[] = {Red[0], Orange[0], Yellow[0], Green[0], Blue[0], Indigo[0], Violet[0]};
int BlueRainbow[] = {Red[1], Orange[1], Yellow[1], Green[1], Blue[1], Indigo[1], Violet[1]};
int GreenRainbow[] = {Red[2], Orange[2], Yellow[2], Green[2], Blue[2], Indigo[2], Violet[2]};
//int Rainbow[] = {RedRainbow[], BlueRainbow[], GreenRainbow[]};



void setup()
{
  Tlc.init();
}

void loop()
{
        for (int r = 0; r<17 ; r++)
        {
          uint32_t startMillisr = r*10;
          tlc_addFade(RedPins[r], Violet[0], Red[0], startMillisr+600, startMillisr+700);
        }
                
        for (int g = 0; g<17; g++)
        {
          uint32_t startMillisg = g*10;
          tlc_addFade(GreenPins[g], Violet[1], Red[1], startMillisg+600, startMillisg+700);
        }
        
        for (int b = 0; b<17; b++)
        {
          uint32_t startMillisb = b*10;
          tlc_addFade(BluePins[b], Violet[2], Red[2], startMillisb+600, startMillisb+700);
        }
   tlc_updateFades();
}

And that yields this:

Okay, I led you down the wrong path because of my inexperience with addFade(). All of the fading I've done with the 5940, I did manually. I completely missed that you did offset the timings for your fades originally. I thought you were using the same start and stop times.

A couple of things to realize: tlc_updateFades() updates the fade status of the channels, based on the current time in millis(). So you should call it periodically to make sure the animations are getting properly updated. Also realize if you set something for millis() + 100 milliseconds but call it 1000 milliseconds later, the time will have already passed.

There's a maximum buffer for the number of active fades. The default buffer is 24 with each one taking up 13 bytes for a total of 312 bytes of RAM. (I mention that because if you increase that number, you need to realize there's a RAM limit.) This is important because in your initial code you were putting 336 fades into a buffer that holds 24...

(FYI, 336 * 13 = 4368 bytes so your out of RAM on a ATmega328).

So your method of trying to queue up all this fading activity simply isn't going to work. Also, you have yet to describe the behavior you actually want. Just videos of what happens. Makes it hard to suggest how to implement anything correctly.

Well your information is always helpful!

I'm trying to just get all of them to be fading through the rainbow. So at any given time, all the colors of the rainbow are being displayed but as time progresses, the positions of the colors changes.

I'll look have to do some math when I get a chance.

the goal is something like this

http://youtu.be/WBn8rV8zzVc

Something like that is probably going to be done best if you manually fade the lights yourself and not rely on addfade().

While the example code isn't using the Arduino functions, it wouldn't take much to figure out how to make them do so.

Whats wrong with addFade? And i dont understand what you mean by manually fading them,

Okay
So at this point, I’m trying to solve the issue of the out of RAM issue and the fade buffer being full.

It will need some clever programming.

Here is my code at this point, although this is the code that overflows the RAM. :

/*  Rainbow TLC5940 Fader
    Shannon Strutz
    8/21/2012
    funkyguy4000.wordpress.com
    
    This code uses two TLC5940 PWM Led Drivers from TI.
    It starts out with Red and fades each led down the line through the rainbow.
    Or at least that is the goal.
*/
#include "Tlc5940.h"
#include "tlc_fades.h"

TLC_CHANNEL_TYPE channel;

//Defining RGB Color pins.  Notice I have each color on their own TLC5940
int RedPins[] = {1,4,7,10,13,17,20,23,26,29,33,36,39,42,45};
int GreenPins[] = {2,5,8,11,14,18,21,24,27,30,34,37,40,43,46};
int BluePins[] = {3,6,9,12,15,19,22,25,28,31,35,38,41,44};

//Defining colors.  Rainbow goes Red->Orange->Yellow->Green->Blue->Indigo->Violet->Repeat
int RRed = 4095;
int BRed = 0;
int GRed = 0;
int Red[] = {RRed, BRed, GRed};

int ROrange = 4094;
int BOrange = 2040;
int GOrange = 0;
int Orange[] = {ROrange, BOrange, GOrange};

int RYellow = 4095;
int BYellow = 4095;
int GYellow = 0;
int Yellow[] = {RYellow, BYellow, GYellow};

int RGreen = 0;
int BGreen = 0;
int GGreen = 4095;
int Green[] = {RGreen, BGreen, GGreen};

int RBlue = 0;
int BBlue = 4095;
int GBlue = 0;
int Blue[] = {RBlue, BBlue, GBlue};

int RIndigo = 1200;
int BIndigo = 2080;
int GIndigo = 0;
int Indigo[] = {RIndigo, BIndigo, GIndigo};

int RViolet = 2288;
int BViolet = 4095;
int GViolet = 0;
int Violet[] = {RViolet, BViolet, GViolet};

int RedRainbow[] = {Red[0], Orange[0], Yellow[0], Green[0], Blue[0], Indigo[0], Violet[0]};
int BlueRainbow[] = {Red[1], Orange[1], Yellow[1], Green[1], Blue[1], Indigo[1], Violet[1]};
int GreenRainbow[] = {Red[2], Orange[2], Yellow[2], Green[2], Blue[2], Indigo[2], Violet[2]};
//int Rainbow[[]] = {RedRainbow[], BlueRainbow[], GreenRainbow[]};



void setup()
{
  Tlc.init();
}

void loop()
{
        for (int r = 0; r<17 ; r++)
        {
          uint32_t startMillisr = r*10;
          tlc_addFade(RedPins[r], Red[0], Orange[0], startMillisr, startMillisr+100);
          tlc_addFade(RedPins[r], Orange[0], Yellow[0], startMillisr+100, startMillisr+200);
          tlc_addFade(RedPins[r], Yellow[0], Green[0], startMillisr+200, startMillisr+300);
          tlc_addFade(RedPins[r], Green[0], Blue[0], startMillisr+300, startMillisr+400);
          tlc_addFade(RedPins[r], Blue[0], Indigo[0], startMillisr+400, startMillisr+500);
          tlc_addFade(RedPins[r], Indigo[0], Violet[0], startMillisr+500, startMillisr+600);
          tlc_addFade(RedPins[r], Violet[0], Red[0], startMillisr+600, startMillisr+700);
        }
                
        for (int g = 0; g<17; g++)
        {
          uint32_t startMillisg = g*10;
          tlc_addFade(GreenPins[g], Red[1], Orange[1], startMillisg, startMillisg+100);
          tlc_addFade(GreenPins[g], Orange[1], Yellow[1], startMillisg+100, startMillisg+200);
          tlc_addFade(GreenPins[g], Yellow[1], Green[1], startMillisg+200, startMillisg+300);
          tlc_addFade(GreenPins[g], Green[1], Blue[1], startMillisg+300, startMillisg+400);
          tlc_addFade(GreenPins[g], Blue[1], Indigo[1], startMillisg+500, startMillisg+500);
          tlc_addFade(GreenPins[g], Indigo[1], Violet[1], startMillisg+600, startMillisg+600);
          tlc_addFade(GreenPins[g], Violet[1], Red[1], startMillisg+700, startMillisg+700);
        }
        
        for (int b = 0; b<17; b++)
        {
          uint32_t startMillisb = b*10;
          tlc_addFade(BluePins[b], Red[2], Orange[2], startMillisb, startMillisb+100);
          tlc_addFade(BluePins[b], Orange[2], Yellow[2], startMillisb+100, startMillisb+200);
          tlc_addFade(BluePins[b], Yellow[2], Green[2], startMillisb+200, startMillisb+300);
          tlc_addFade(BluePins[b], Green[2], Blue[2], startMillisb+300, startMillisb+400);
          tlc_addFade(BluePins[b], Blue[2], Indigo[2], startMillisb+500, startMillisb+500);
          tlc_addFade(BluePins[b], Indigo[2], Violet[2], startMillisb+600, startMillisb+600);
          tlc_addFade(BluePins[b], Violet[2], Red[2], startMillisb+600, startMillisb+700);
        }
   tlc_updateFades();
}