Go Down

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

nyg78

#15
Feb 09, 2012, 05:18 pm

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

#16
Feb 09, 2012, 05:53 pm
Did you do a:-
Code: [Select]
` Tlc.update();`
after the loop to transfer the new data to the LEDs?

nyg78

#17
Feb 10, 2012, 02:12 pm
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

#18
Feb 10, 2012, 02:20 pm
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

#19
Feb 11, 2012, 01:58 pm
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

#20
Feb 11, 2012, 02:54 pm
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.

dxw00d

#21
Feb 11, 2012, 02:59 pm
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

#22
Feb 12, 2012, 12:28 am
Quote
Wrong way round?

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

dxw00d

#23
Feb 12, 2012, 11:39 am
No point, other than reducing confusion. Just being a benevolent deity.

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

nyg78

#24
Feb 12, 2012, 02:39 pm
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

#25
Feb 12, 2012, 02:49 pm
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.

nyg78

#26
Feb 12, 2012, 02:56 pm

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

#27
Feb 12, 2012, 03:12 pm
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

#28
Feb 12, 2012, 03:14 pm
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.

nyg78

#29
Feb 12, 2012, 03:46 pm
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