麽麽茶㊣ 发表于 2014-4-11 11:00:26

TLC5940 PWM扩展

本帖最后由 麽麽茶㊣ 于 2014-4-11 14:17 编辑

arduino 占用7个口,1个TLC5940扩展16个口    2个芯片控制16*2个口

引脚图



接线图


例子中有对应连接的说明
    Basic Pin setup:
    ------------                                  ---u----
    ARDUINO   13|-> SCLK (pin 25)         OUT1 |1   28| OUT channel 0
            12|                           OUT2 |2   27|-> GND (VPRG)
            11|-> SIN (pin 26)            OUT3 |3   26|-> SIN (pin 11)
            10|-> BLANK (pin 23)          OUT4 |4   25|-> SCLK (pin 13)
               9|-> XLAT (pin 24)             .|5   24|-> XLAT (pin 9)
               8|                           .|6   23|-> BLANK (pin 10) 10K 5V
               7|                           .|7   22|-> GND
               6|                           .|8   21|-> VCC (+5V)
               5|                           .|9   20|-> 2K Resistor -> GND
               4|                           .|10    19|-> +5V (DCPRG)
               3|-> GSCLK (pin 18)            .|11    18|-> GSCLK (pin 3)
               2|                           .|12    17|-> SOUT
               1|                           .|13    16|-> XERR
               0|                           OUT14|14    15| OUT channel 15
    ------------                                  --------

    -+5V from Arduino -> TLC pin 21 and 19   (VCC and DCPRG)
    -GND from Arduino -> TLC pin 22 and 27   (GND and VPRG)
    -digital 3      -> TLC pin 18            (GSCLK)
    -digital 9      -> TLC pin 24            (XLAT)
    -digital 10       -> TLC pin 23            (BLANK)
    -digital 11       -> TLC pin 26            (SIN)
    -digital 13       -> TLC pin 25            (SCLK)
    -The 2K resistor between TLC pin 20 and GND will let ~20mA through each
       LED.To be precise, it's I = 39.06 / R (in ohms).


代码
#include "Tlc5940.h"

void setup()
{
Tlc.init(0);// Call Tlc.init() to setup the tlc.
}

void loop()
{
for(int i = 0; i < 4095; i+=10)
{
    Tlc.set(1, i);
    Tlc.set(4, i);
    Tlc.set(7, i);
    Tlc.update();
    delay(5);
}

for(int i = 4095; i > 0; i-=10)
{
    Tlc.set(1, i);
    Tlc.set(4, i);
    Tlc.set(7, i);
    Tlc.update();
    delay(5);
}
}


Tlc.update();
update在设置好所有端口,PWM后使用。

如果有两个芯片,set的端口号从16开始计数。


实验:


结贴!

补充: 外接元件只能共阳。共阴的用不了。

鱼在人的江湖 发表于 2014-11-2 21:20:47

大侠,感谢你的分享,我正在做关于TLC5940驱动全彩LED灯光效果,请问有没有完整的TLC5940的代码程序,有的话请您发我一份,万份感激! 我的邮箱:[email protected]   :):):):):)

bigmango 发表于 2015-3-24 21:21:22

刚刚也搭了一个简单的测试,确实不错5个口就完成了16~XXXX个pwm的输出,太好了.

892720757 发表于 2015-4-4 15:25:49

bigmango 发表于 2015-3-24 21:21 static/image/common/back.gif
刚刚也搭了一个简单的测试,确实不错5个口就完成了16~XXXX个pwm的输出,太好了.

大神能发给我一份驱动程序吗,小弟刚刚入门,自己写不出来。我邮箱[email protected]。。感激不尽

bigmango 发表于 2015-4-20 10:29:24

自己下载啊,官网就有驱动.

wukongxuetang 发表于 2015-7-6 13:26:10

892720757 发表于 2015-4-4 15:25 static/image/common/back.gif
大神能发给我一份驱动程序吗,小弟刚刚入门,自己写不出来。我邮箱。。感激不尽

#include "Tlc5940.h"
void setup()
{
Tlc.init();
#define mils 10
#define STEP 1
#define red

}
void loop()
{

//There are 4095 steps from off 0 to max on 4095.
//Reference Color defined as RC
//The color you would like to be the dominant color will be the reference color
//Secondary dim colors to be combined will be referenced to RC



int r = 0;
int g = 0;
int b = 0;


   for(int RC=0;RC<4095;RC=RC+STEP){
   r = RC;
///////////////////RED LEDs
Tlc.set(0, r);
Tlc.set(3, r);
Tlc.set(6, r);
Tlc.set(9, r);
Tlc.set(12, r);
Tlc.set(15, r);
Tlc.set(18, r);
Tlc.set(21, r);
///////////////////Green LEDS
Tlc.set(1, g);
Tlc.set(4, g);
Tlc.set(7, g);
Tlc.set(10, g);   
Tlc.set(13, g);
Tlc.set(16, g);
Tlc.set(19, g);   
Tlc.set(22, g);
///////////////////Blue LEDS
Tlc.set(2, b);
Tlc.set(5, b);
Tlc.set(8, b);
Tlc.set(11, b);   
Tlc.set(14, b);
Tlc.set(17, b);
Tlc.set(20, b);   
Tlc.set(23, b);   
   
Tlc.update();
delay(mils);
}
for(int RC=4095;RC>0;RC=RC-STEP){
   r = RC;
///////////////////RED LEDs
Tlc.set(0, r);
Tlc.set(3, r);
Tlc.set(6, r);
Tlc.set(9, r);
Tlc.set(12, r);
Tlc.set(15, r);
Tlc.set(18, r);
Tlc.set(21, r);
///////////////////Green LEDS
Tlc.set(1, g);
Tlc.set(4, g);
Tlc.set(7, g);
Tlc.set(10, g);
Tlc.set(13, g);
Tlc.set(16, g);
Tlc.set(19, g);
Tlc.set(22, g);
///////////////////Blue LEDS
Tlc.set(2, b);
Tlc.set(5, b);
Tlc.set(8, b);
Tlc.set(11, b);
Tlc.set(14, b);
Tlc.set(17, b);
Tlc.set(20, b);
Tlc.set(23, b);   

Tlc.update();
delay(mils);
}
}

努力微笑 发表于 2015-7-13 15:31:50

可以控制舵机嘛

xin6602 发表于 2017-6-29 21:59:48

"Tlc5940.h"。麻烦楼主发一下这个库文件吧,谢谢!

xin6602 发表于 2017-6-30 10:06:53

找到了。大家这个链接试试:https://github.com/mcous/TLC5940

xin6602 发表于 2017-6-30 10:33:34

试了下,这个可用。https://github.com/hideyukisaito/Tlc5940

xin6602 发表于 2017-7-5 15:26:30

bigmango 发表于 2015-3-24 21:21
刚刚也搭了一个简单的测试,确实不错5个口就完成了16~XXXX个pwm的输出,太好了.

我也测试了下,第一个芯片控制是正常的,第二、第三个芯片就没有按程序的控制点亮,不知为什么?

xin6602 发表于 2017-7-5 21:38:35

问题解决,需要改“tlc_config.h”

bigmango 发表于 2017-9-23 12:07:33

怎么改的,发出来参考一下咯
页: [1]
查看完整版本: TLC5940 PWM扩展