From Arduino MEGA PWM to TLC5940 PWM code change

Hi all,

I have purchased some TLC5940's to experiment with I understand this chip provides 16 PWM outputs and can be daisy chained to give more such as 16, 32, 48 and 64 outputs etc.

I need to wait until they arrive in the mail, should only be a few days, in the meantime I would like to understand the changes to my code that would be required to address the PWM pins on the TLC rather then the MEGAs pins.. which I am using analogWrite.

I've also read that I may need to modify Tlc5940.h a file inside the TLC library to enable usage or more than 1 TLC chip.. but If I can use MEGA and TLC's PWMs together I might get away with using only 1 TLC. I might for simplicity just use the Tlc chips tho.

I have a requirment to drive 28 channels of PWM which will be fed by 14 Sensors... each Thermal sensor will use 2 PWMs to bring a BLUE/RED colour change on LEDs to represent heat load in colour.

So I have read up on the TLC and understand that I need to INCLUDE it's code. info I have is from this page,

so I need to add the following line to the beginning of my code.
#include "Tlc5940.h"

To access a PWM pin I need to use
Tlc.set(channel, brightness);
EG: Tlc.set(0, 4095);

Then I need to Run UPDATE to make the code sent to TLC Chip
Tlc.update();

This is a portion of my code which handles the PWM lighting,
in void setup I am using pinMode to assign the pins.
eg:
pinMode(12, OUTPUT) for assigning the pins

here is a part of my code which fades a PWM from off to on and off again, I have used this at the start to act like a demo / self test all LEDs work etc.. I make it fade red and blue.. this is only part of the code. for RED

analogWrite(12, brightness); //Brightness is = 0 as I have set that at the start of code. 

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount; //fadeamount = 5

// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255){
fadeAmount = -fadeAmount;}

so In my code I am doing analogWrite to 12th Pin

would I be changing the code to the following?

Tlc.set(12, brightness);//Brightness = 0 as I set that at the start of code using "int brightness = 0".

// change the brightness for next time through the loop:
brightness = brightness + fadeAmount; //fadeamount = 5 ive also set that using "int fadeamount = 5"

// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255){
fadeAmount = -fadeAmount;}

Where do I place Tlc.update
and the tlc chip has 4096 levels of fade where I think arduino mega/uno only use 1024?
so i am going to need to alter this in my code to account for? can anyone verify this for me

in the other part of my code where I am doing the conversion of the sensor to the LED
the pwms are also being commanded via analogWrite, do I simply change them to Tlc.set

lastly pinMode, am i suppose to use that?

cheers
Shaun

Beam me up Scotty.. (bump)