想在室内营造一点小氛围不,话说工程师工作繁忙也得自己造些情调不是。这我是在pcDuino上做的,接一个灯带驱动模块LED strip driver,链接文章里用的Arduino,附有程序代码,在pcDuino上点亮的话程序代码我也会附上的。为了使效果更好,LED灯带我设计的是呼吸灯哦!
LED strip driver模块
LED灯带(5m)
接线很简单
LED strip driver CLK –> pcDuino D2
LED strip driver DIN –> pcDuino D3
打开ubuntu编译运行程序代码
点亮后的5m灯带效果,这里是拍出来的照片,灯带亮度逐渐变化的效果不是很明显,但是它是会“呼吸”的,很漂亮吧
程序代码:
#include "core.h"
#define uint8_t unsigned char
#define uint32_t unsigned long
uint8_t Clkpin;
uint8_t Datapin;
void RGBdriver(uint8_t Clk, uint8_t Data)
{
Clkpin = Clk;
Datapin = Data;
pinMode(Datapin, OUTPUT);
pinMode(Clkpin, OUTPUT);
}
void ClkRise(void)
{
digitalWrite(Clkpin, LOW);
delayMicroseconds(1);
digitalWrite(Clkpin, HIGH);
delayMicroseconds(1);
}
void Send32Zero(void)
{
unsigned char i;
for (i=0; i<32; i++)
{
digitalWrite(Datapin, LOW);
ClkRise();
}
}
void begin(void)
{
Send32Zero();
}
void end(void)
{
Send32Zero();
}
uint8_t TakeAntiCode(uint8_t dat)
{
uint8_t tmp = 0;
if ((dat & 0x80) == 0)
{
tmp |= 0x02;
}
if ((dat & 0x40) == 0)
{
tmp |= 0x01;
}
return tmp;
}
// gray data
void DatSend(uint32_t dx)
{
uint8_t i;
for (i=0; i<32; i++)
{
if ((dx & 0x80000000) != 0)
{
digitalWrite(Datapin, HIGH);
}
else
{
digitalWrite(Datapin, LOW);
}
dx <<= 1;
ClkRise();
}
}
// Set color
void SetColor(uint8_t Red,uint8_t Green,uint8_t Blue)
{
uint32_t dx = 0;
dx |= (uint32_t)0x03 << 30; // highest two bits 1锛宖lag bits
dx |= (uint32_t)TakeAntiCode(Blue) << 28;
dx |= (uint32_t)TakeAntiCode(Green) << 26;
dx |= (uint32_t)TakeAntiCode(Red) << 24;
dx |= (uint32_t)Blue << 16;
dx |= (uint32_t)Green << 8;
dx |= Red;
DatSend(dx);
}
void setup()
{
RGBdriver(2,3);
}
void loop()
{
unsigned int i;
while(1)
{
for(i = 0;i < 256;i ++)
{
begin(); // begin
SetColor(0,0,i); //Blue. First node data. SetColor(R,G,B)
end();
//delay(1);
}
for(i = 255;i > 0;i --)
{
begin(); // begin
SetColor(0,0,i); //Blue. first node data
end();
//delay(1);
}
}
}
来源:oschina
链接:https://my.oschina.net/u/1174645/blog/141966