arduino PWM with a TLC5940


Example

The TLC5940 is a handy item to have when you run out of PWM ports on the Arduino. It has 16 channels, each individually controllable with 12 bits of resolution (0-4095). An existing library is available at http://playground.arduino.cc/Learning/TLC5940. It is useful for controlling multiple servos or RGB LEDs. Just keep in mind, the LEDs must be common anode to work. Also, the chips are daisy-chainable, allowing even more PWM ports.

Example:

// Include the library
#include <Tlc5940.h>

void setup() {
    // Initialize
    Tlc.init();
    Tlc.clear(); 
}

unsigned int level = 0;
void loop() {
    // Set all 16 outputs to same value
    for (int i = 0; i < 16; i++) {
        Tlc.set(i, level);
    }
    level = (level + 1) % 4096;
    // Tell the library to send the values to the chip
    Tlc.update();
    delay(10);
}