极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 28839|回复: 12

TLC5940 PWM扩展

[复制链接]
发表于 2014-4-11 11:00:26 | 显示全部楼层 |阅读模式
本帖最后由 麽麽茶㊣ 于 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).  


代码
  1. #include "Tlc5940.h"

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

  6. void loop()
  7. {
  8.   for(int i = 0; i < 4095; i+=10)
  9.   {
  10.     Tlc.set(1, i);
  11.     Tlc.set(4, i);
  12.     Tlc.set(7, i);
  13.     Tlc.update();
  14.     delay(5);
  15.   }
  16.   
  17.   for(int i = 4095; i > 0; i-=10)
  18.   {
  19.     Tlc.set(1, i);
  20.     Tlc.set(4, i);
  21.     Tlc.set(7, i);
  22.     Tlc.update();
  23.     delay(5);
  24.   }
  25. }
复制代码


  1. Tlc.update();
复制代码

update在设置好所有端口,PWM后使用。

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


实验:


结贴!

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2014-11-2 21:20:47 | 显示全部楼层
大侠,感谢你的分享,我正在做关于TLC5940驱动全彩LED灯光效果,请问有没有完整的TLC5940的代码程序,有的话请您发我一份,万份感激! 我的邮箱:[email protected]   
回复 支持 反对

使用道具 举报

发表于 2015-3-24 21:21:22 | 显示全部楼层
刚刚也搭了一个简单的测试,确实不错5个口就完成了16~XXXX个pwm的输出,太好了.
回复 支持 反对

使用道具 举报

发表于 2015-4-4 15:25:49 | 显示全部楼层
bigmango 发表于 2015-3-24 21:21
刚刚也搭了一个简单的测试,确实不错5个口就完成了16~XXXX个pwm的输出,太好了.

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

使用道具 举报

发表于 2015-4-20 10:29:24 | 显示全部楼层
自己下载啊,官网就有驱动.
回复 支持 反对

使用道具 举报

发表于 2015-7-6 13:26:10 | 显示全部楼层
892720757 发表于 2015-4-4 15:25
大神能发给我一份驱动程序吗,小弟刚刚入门,自己写不出来。我邮箱。。感激不尽

#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 | 显示全部楼层
可以控制舵机嘛
回复 支持 反对

使用道具 举报

发表于 2017-6-29 21:59:48 | 显示全部楼层
"Tlc5940.h"。麻烦楼主发一下这个库文件吧,谢谢!
回复 支持 反对

使用道具 举报

发表于 2017-6-30 10:06:53 | 显示全部楼层
找到了。大家这个链接试试:https://github.com/mcous/TLC5940
回复 支持 反对

使用道具 举报

发表于 2017-6-30 10:33:34 | 显示全部楼层
试了下,这个可用。https://github.com/hideyukisaito/Tlc5940
回复 支持 反对

使用道具 举报

发表于 2017-7-5 15:26:30 | 显示全部楼层
bigmango 发表于 2015-3-24 21:21
刚刚也搭了一个简单的测试,确实不错5个口就完成了16~XXXX个pwm的输出,太好了.

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

使用道具 举报

发表于 2017-7-5 21:38:35 | 显示全部楼层
问题解决,需要改“tlc_config.h”
回复 支持 反对

使用道具 举报

发表于 2017-9-23 12:07:33 | 显示全部楼层
怎么改的,发出来参考一下咯
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-25 17:28 , Processed in 0.047104 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表