Go Down

Topic: TLC5940 help, adding LEDs causes weird flashing (Read 11884 times) previous topic - next topic

nyg78


Quote
If I want the odd channels on together (ex. 1, 3, 5, etc.), then turn them off and turn on the even channels (ex. 0, 2, 4, etc.)  then repeat, do I need to use an array?

No you can do that algorithmically.
Code: [Select]
for(int i=0; i<24; i++)
{
  if(i & 1) Tlc.set(i, 2047); else Tlc.set(i, 0);
}

Would set odd numbers on and even numbers off so how do you think you can do the opposite?


I thought it would be:
Code: [Select]


for(int i=1; i<24; i++)
{
  if(i & 1) Tlc.set(i, 2047); else Tlc.set(i, 0);
}


but it didn't change.  What am I missing?

Grumpy_Mike

Did you do a:-
Code: [Select]
Tlc.update();
after the loop to transfer the new data to the LEDs?

nyg78

Here's what I tried:
Code: [Select]

#include "Tlc5940.h"

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

void loop() {

for(int i=0; i<24; i++)
  if(i & 1) Tlc.set(i, 2047);
  else Tlc.set(i, 0);

Tlc.update();
}


This lights the odd channels, where it should be lighting the even channels.  If I make one change:
Code: [Select]

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


It still lights the odd channels.

dxw00d

Quote
It still lights the odd channels.


It will. You haven't changed the bit that sets the odd/even channels, you just changed the starting channel.

This...
Code: [Select]
  if(i & 1) Tlc.set(i, 2047);
  else Tlc.set(i, 0);

sets odd values of i (channels) to 2047 (presumably fully on), and even values to 0.

Try swapping the 2047 and the 0.

nyg78

Thank you, that worked.  I tried an array but didn't quite get it to work right.  Here's what I have:

Code: [Select]

#include "Tlc5940.h"

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};
boolean two [24] = {0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047, 0, 2047 };
int pattern2 [12] = {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], one[i]); //even channels
  delay(500);
  Tlc.update();
  Tlc.clear();

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


I put a delay in there just to see if the patterns are right.  It changes patterns but not all of the LEDs come on like they're supposed to.  It also seems dimmer than it's supposed to be.

PaulS

Code: [Select]
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.

Code: [Select]
  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.
The art of getting good answers lies in asking good questions.

dxw00d

Code: [Select]
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};

Quote
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?

PaulS

Quote
Wrong way round?

Yeah. So, what's your point? It was early...
The art of getting good answers lies in asking good questions.

dxw00d

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

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

nyg78

Quote
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:

Quote

Code: [Select]
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.

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

nyg78


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? 

dxw00d

These arrays need to be the same length.
Code: [Select]
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
Code: [Select]
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.

PaulS

Quote
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.
The art of getting good answers lies in asking good questions.

nyg78

Like this?
Code: [Select]

#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.

Go Up