Pages: [1]   Go Down
Author Topic: Tlc5940 rgb led rainbow  (Read 1361 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys,

I'm trying to create a rainbow like wave using 3 tlc5940 led driver and 16 rgb LEDs. The problem is that I don't know where to start with this rgb rainbow wave. If some one could point me into the right direction. It would be helpful. Thanks
« Last Edit: November 11, 2011, 10:10:33 pm by krazyhorze » Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't know what you mean by wave, I can guess but I don't know.

16 leds capable of 18-bit color using 6 bits each element from the TLC5940. Nice.

Rainbow is red,orange,yellow,green, blue,indigo,violet ... how perfectly do you want to mimic rainbow hues and sequence?

So you have to mix red/green/blue to get those colors.

Perhaps you should make a mini-project using 1 RGB led just to find out what mixing you can do? Or you can use your PC. For example Windows Paint allows you to define custom colors. The RGB ranges used on mine allow 8 bits each while the TLC5940 uses 6 bits. Numbers I would take would have to be divided by 4 to work.

There are programs that slowly change 1 lead at a time on an RGB led from 0 to full. I don't think that you'll get a rainbow sequence that way but it's still interesting.


Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One method of color generation is to:

green starts at max
[loop]
red up
green down
blue up
red down
green up
blue down
[/loop]

each up would be
Code:
for (int i=0;i<=255;i++) analogWrite(pin, i), delay(50);
and each down would be
Code:
for (int i=255;i>=0;i++) analogWrite(pin, i), delay(50);

One potential problem is that human vision is logarithmic, so it will look like it's getting brighter quickly at the beginning and then slowing down. So you could do something like
Code:
for (int i=0;i<=255;i=pow(i,2)) analogWrite(pin, i), delay(50); //pow won't actually work here since it uses floating point math, and there really isn't a good built-in power function for integers. Huh.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys, but what I'm looking for is more like this


where one color move over one and it continues.
Raising and lowering the grey scale also product the rgb effect of rainbow but I'm trying to make it like the one in the video. I just don't know where to start!
Logged

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, the Uno only has 6 PWM pins - enough for 2 RBG LEDs, and even the Mega only has 16. Once you figure out the hardware, just write down *exactly* what you want each channel (red, green, or blue) of each led to do at any time, like I did with the "blue up" thing.

Another example:
LED1 raise 0 to max power over 1 second
LED2 lower max to 0 power over 2 seconds
LED3 raise 0 to max power and LED4 lower max to 0 power over 1.2 seconds
...

Once you get to actually programming it, one (really memory inefficient) way of doing it is to say that you'll update every LED every 50 or so milliseconds, and then make an array for each channel of each LED that says what value it will be at that time.

For example, if you wanted to raise LED1 and then, after 200 milliseconds, start raising LED2, you could do:
Code:
LED1greenColors[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ,19};
LED2greenColors[] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};

void loop() {
  static unsigned int i=0;
  analogWrite(led1green, LED1greenColors[i];
  analogWrite(led2green, LED2greenColors[i];
  i++;
}
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I gotcha Krazyhorze. You want certain colors for each led and then appear to move the colors together.

Why I suggest the small project, you need to gather data for the colors you will use as sets of red,green,blue for each color.

I don't know the TLC5920 library and I don't want to right now so you'll have to deal with that part. But I do see you can communicate with it via serial, you aren't stuck there!

Get your data together to make each led the starting color. Since you have 16 leds with 3 elements each and 3 16 pin led drivers you might want to use each driver to control one element of each led. If you do then organize your data as a 16x3 int array (I see the TLC has 0-4095 steps PWM output on each pin.).

Data array will look like Color[led][element] where leds are 0-15 and elements(the RGB of each) are 0-2.

// this is about how you would load the 16 leds with color
for (index=0; index<16; index++) {
  for (element=0; element<3; element++) {
    // here you transmit Color[index][element] to the TLC matching 'element'
    // element=0 would go to the 1st TLC, 1 would go to 2nd and 2 would go to 3rd
  }
}

But you want the colors to move! So you need a number to offset which led gets what color. 1st time you write the 1st color to led 0, 2nd to led 1, etc until 16th color to led 15. Then pause long enough to see them all, maybe 1/4 second? And then you write the 2nd color to led 0, etc, and led 15 gets 1st color.
 
The way to do that is to change Color[index][element] to Color[(index + offset) & 15][element].
You set the offset before the 'for (index' loop by
offset = (offset+1) & 15;

Basically I''m too tired to explain more right now so I hope you get it.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. I'll try the 2d array and see if it works.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Back awake and I'm wondering if those TLC's are shift registers? There may be functions in the library that let you push a value into a TLC that will move the others up a led for you. Then you'd just need to push a number for red into the TLC that runs the red elements, green for the next TLC and blue for the last, then a short delay and on to the next color.

 
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah they have. im gonna start messing with the fade function to see if it'll work.
Logged

Pages: [1]   Go Up
Jump to: