TLC5940 help, adding LEDs causes weird flashing

for(int i=0; i<24; i++) Tlc.set(pattern1[i], one[i]); //even channels

That is going to reference pattern1[0] through pattern1[23] which is OK. It will also reference one[0] through one[23] which is NOT OK.

  delay(500);
  Tlc.update();
  Tlc.clear();

Now, I’ve never used this library, but this order just looks wrong. I would expect to update the display, then pause for half a second, then clear the display.

boolean one [24] = {2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0};
int pattern1 [12] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22};

That is going to reference pattern1[0] through pattern1[23] which is OK. It will also reference one[0] through one[23] which is NOT OK.

Wrong way round?

Wrong way round?

Yeah. So, what's your point? It was early...

No point, other than reducing confusion. Just being a benevolent deity.

Seriously, who though 'God Member' was a good idea.

Now, I’ve never used this library, but this order just looks wrong. I would expect to update the display, then pause for half a second, then clear the display.

Ok, fixed that. Now how do I fix this:

for(int i=0; i<24; i++) Tlc.set(pattern1[i], one[i]); //even channels

That is going to reference pattern1[0] through pattern1[23] which is OK. It will also reference one[0] through one[23] which is NOT OK.

Ok, fixed that. Now how do I fix this:

Both arrays need to be the same size, if you plan to reference every element in each array.

PaulS: Both arrays need to be the same size, if you plan to reference every element in each array.

They each have 12 LEDs on and 12 off at once, so they are the same size. Or no?

These arrays need to be the same length.

boolean one [24] = {2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0};
int pattern1 [12] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22};

Either one is too long, or pattern1 is too short. If it’s the former, then

for(int i=0; i<24; i++) Tlc.set(pattern1[i], one[i]);

is wrong. What would happen when i was 12 or more?

The same goes for the other pair of arrays.

They each have 12 LEDs on and 12 off at once, so they are the same size. Or no?

No.
boolean one [24] = {2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0};
int pattern1 [12] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22};

You want to set some pins on and some pins off. If you want to put the pattern (on or off) in the array, the array length should be 24, and you don’t need a pin number array.

If you want the array to contain only the pins to be on, then you don’t need the pattern array. The array that you do use would contain the pin numbers to turn on. The array then needs to be up to 25 elements long, though it can be much shorter (if only a few pins are to be on), but the first value in the array needs to define the length of the array.

Like this?

#include "Tlc5940.h"

int pattern1 [24]= {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22};
int pattern2 [24] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23};

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

void loop() {

for(int i=0; i<24; i++) 
  Tlc.set(pattern1[i], 2047); //even channels
  Tlc.update();
  delay(500);
  Tlc.clear();

for(int i=0; i<24; i++) 
  Tlc.set(pattern2[i], 2047); //odd channels
  Tlc.update();
  delay(500);
  Tlc.clear();
}

There are two problems with it though. Channel 0 stays on during both patterns. Also, the brightness level I set of 2047 doesn’t seem to be working, it looks like it is full brightness.

Like this?

If the arrays are to be pins to turn on, then the first thing that you need to do is turn all pins off. Then, turn the pins in the array on.

You also need to make sure that your loop index does not run off the end of the array (as yours do).

PaulS: If the arrays are to be pins to turn on, then the first thing that you need to do is turn all pins off. Then, turn the pins in the array on.

By adding a "Tlc.clear();" before each "for" in the "void loop" section?

You also need to make sure that your loop index does not run off the end of the array (as yours do).

Not sure what you mean by this.

By adding a “Tlc.clear();” before each “for” in the “void loop” section?

If that actually turns all pins off, yes.

Not sure what you mean by this.

int pattern2 [24] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23};

But, you only provide 12 initial values.

for(int i=0; i<24; i++) 
  Tlc.set(pattern1[i], 2047); //even channels

Then, you access all 24 of them.

PaulS:

Not sure what you mean by this.

int pattern2 [24] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23};

But, you only provide 12 initial values.

for(int i=0; i<24; i++) 

Tlc.set(pattern1[i], 2047); //even channels



Then, you access all 24 of them.

Changed the “i<24;” to “i<12;” and now it works. So this number will be how many LEDs I have in the array I want to use?

So this number will be how many LEDs I have in the array I want to use?

It will be the number of pin numbers in the array. It's really hard to put an LED in an array.

Starting to understand it now. I ran into a problem that I can’t figure out. I’m trying out different patterns and came up with the following, which works, but for some reason instead of starting on pattern1 and going up,it starts on pattern2 and goes up.

#include "Tlc5940.h"

int pattern1 [24]= {0, 4, 8, 12, 16, 20};
int pattern2 [24]= {1, 5, 9, 13, 17, 21};
int pattern3 [24]= {2, 6, 10, 14, 18, 22};
int pattern4 [24]= {3, 7, 11, 15, 19, 23};

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

void loop() {
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern1[i], 2047); 
  Tlc.update();
  delay(500);
  
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern2[i], 2047); 
  Tlc.update();
  delay(500);
  
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern3[i], 2047);
  Tlc.update();
  delay(500);
  
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern4[i], 2047); 
  Tlc.update();
  delay(500);
}
int pattern1 [24]= {0, 4, 8, 12, 16, 20};

Why are the arrays so large?

instead of starting on pattern1 and going up,it starts on pattern2 and goes up.

Does it ever show pattern1?

I'd remove the last three blocks of code, and see what happens. Perhaps the issue is simply that pattern1 does not look like you think it does.

PaulS: int pattern1 [24]= {0, 4, 8, 12, 16, 20};

Why are the arrays so large?

Oops, fixed that.

instead of starting on pattern1 and going up,it starts on pattern2 and goes up.

Does it ever show pattern1? [/quote] Yes. I want it to go pattern 1, 2, 3, 4, but it goes 2, 3, 4, 1 in that order. I've uploaded it a few times to see it there was an issue uploading but everytime it does the same thing.

Yes. I want it to go pattern 1, 2, 3, 4, but it goes 2, 3, 4, 1 in that order. I've uploaded it a few times to see it there was an issue uploading but everytime it does the same thing.

That's why I suggested not showing 4 patterns. Just show pattern1 over and over. Is what is displayed what you expect to see for pattern1?

Yes. All of these patterns are the same, just start and end at different pins/LEDs. I could rearrange the code so that I get the results I want like this:

void loop() {
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern4[i], 2047); 
  Tlc.update();
  delay(500);
  
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern1[i], 2047); 
  Tlc.update();
  delay(500);
  
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern2[i], 2047);
  Tlc.update();
  delay(500);
  
  Tlc.clear();
  for(int i=0; i<6; i++) 
  Tlc.set(pattern3[i], 2047); 
  Tlc.update();
  delay(500);
}

When I use this, it actually runs pattern 1, 2, 3, then 4 in that order. I could do it this way, but I was just trying to see why it won’t work the way one would think it would work.