PWM 与 TLC5940

当你在 Arduino 上耗尽 PWM 端口时, TLC5940 是一个方便的项目。它有 16 个通道,每个通道可独立控制,分辨率为 12 位(0-4095)。现有的库可以在 http://playground.arduino.cc/Learning/TLC5940 上找到 。它对于控制多个伺服或 RGB LED 非常有用。请记住,LED 必须是共阳极才能工作。此外,这些芯片采用菊花链式连接,可实现更多 PWM 端口。

例:

// 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);
}