标题:
WS2811灯光系统单片机程序 22路全彩控制器
[打印本页]
作者:
15918766121
时间:
2016-7-1 12:07
标题:
WS2811灯光系统单片机程序 22路全彩控制器
WS2811灯光程序,单片机22路全彩控制器.
1、从左往右扫
2、从右往左扫
3、从中间向两边扫
4、从两边向中间扫
单片机源程序如下:
#include "includes.h"
//T_POINT idata szPoint[20];
#if 0
DelayN10ms(100);
pt.r=10;pt.g=0,pt.b=0;
memcpy(&szPoint[0],&pt,sizeof(T_POINT));
pt.r=0;pt.g=10,pt.b=0;
memcpy(&szPoint[1],&pt,sizeof(T_POINT));
pt.r=0;pt.g=0,pt.b=10;
memcpy(&szPoint[2],&pt,sizeof(T_POINT));
WS2811_Setout(&szPoint,3);
#endif
T_POINT code Design2[]=
{
#if 1
{255,0,42},
{255,0,78},
{255,0,184},
{248,0,255},
{177,0,255},
{71,0,255},
{0,42,255},
{0,113,255},
{0,184,255},
{0,220,255},
{0,255,255},
{0,255,213},
{0,255,142},
{78,255,71},
{149,255,0},
{220,255,0},
{255,213,0},
{255,177,0},
{255,71,0},
{255,0,0},
#else
{10,0,0},
{0,10,0},
{0,0,10},
{10,0,0},
{0,10,0},
{0,0,10},
{10,0,0},
{0,10,0},
{0,0,10},
{10,0,0},
{0,10,0},
{0,0,10},
{10,0,0},
{0,10,0},
{0,0,10},
{10,0,0},
{0,10,0},
{0,0,10},
{10,0,0},
{0,10,0},
#endif
};
T_POINT code Design[]=
{
{255,0,0},
{255,0,10},
{255,0,20},
{255,0,30},
{255,0,42},
{255,0,50},
{255,0,58},
{255,0,66},
{255,0,72},
{255,0,78},
{255,0,90},
{255,0,110},
{255,0,130},
{255,0,150},
{255,0,184},
{245,0,200},
{230,0,215},
{222,0,230},
{200,0,238},
{190,0,245},
{177,0,255},
{160,0,255},
{140,0,255},
{130,0,255},
{120,0,255},
{110,0,255},
{100,0,255},
{95,0,255},
{85,0,255},
{71,0,255},
{56,8,255},
{40,16,255},
{30,24,255},
{20,32,255},
{10,36,255},
{0,42,255},
{0,57,255},
{0,72,255},
{0,87,255},
{0,95,255},
{0,98,255},
{0,102,255},
{0,113,255},
{0,184,255},
{0,190,255},
{0,200,255},
{0,210,255},
{0,220,255},
{0,230,255},
{0,240,255},
{0,255,255},
{0,255,245},
{0,255,235},
{0,255,225},
{0,255,215},
{0,255,200},
{0,255,190},
{0,255,180},
{0,255,170},
{10,255,160},
{20,255,150},
{30,255,140},
{40,255,130},
{50,255,120},
{60,255,110},
{70,255,100},
{78,255,90},
{90,255,80},
{95,255,71},
{100,255,60},
{105,255,50},
{110,255,40},
{120,255,30},
{130,255,20},
{140,255,10},
{149,255,0},
{160,255,0},
{170,255,0},
{180,255,0},
{190,255,0},
{200,255,0},
{210,255,0},
{220,255,0},
{230,245,0},
{240,235,0},
{245,225,0},
{255,213,0},
{255,208,0},
{255,200,0},
{255,190,0},
{255,180,0},
{255,177,0},
{255,170,0},
{255,160,0},
{255,150,0},
{255,140,0},
{255,130,0},
{255,120,0},
{255,110,0},
{255,100,0},
{255,90,0},
{255,80,0},
{255,75,0},
{255,60,0},
{255,50,0},
{255,40,0},
{255,30,0},
{255,20,0},
{255,10,0},
{255,0,0},
};
void WS2811_Setout2(int index)
{//748
int k=10;
uchar cnt=0;
while(1)
{
WS2811_SendByte(Design[index].r);
WS2811_SendByte(Design[index].b);
WS2811_SendByte(Design[index].g);
index++;
if(index==110)
{
index=0;
}
if(++cnt==110)
{
break;
}
}
IO_DIN=1;
IO_DIN=0;
while(k--)
{
_nop_();
}
}
void WS2811_Setout4(int index)
{//748
int k=10;
uchar cnt=0;
while(1)
{
WS2811_SendByte(Design[index].r);
WS2811_SendByte(Design[index].b);
WS2811_SendByte(Design[index].g);
index+=2;
if(index>=110)
{
index=0;
}
if(++cnt==55)
{
break;
}
}
cnt=0;
while(1)
{
WS2811_SendByte(Design[index].r);
WS2811_SendByte(Design[index].b);
WS2811_SendByte(Design[index].g);
index-=2;
if(index<0)
{
index=109;
}
if(++cnt==55)
{
break;
}
}
IO_DIN=1;
IO_DIN=0;
while(k--)
{
_nop_();
}
}
void WS2811_Setout3(int index)
{//748
int k=10;
uchar cnt=0,n;
// while(1)
{
//----------------
for(n=0;n<4;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<4;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<3;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<3;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<3;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<2;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<2;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<2;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<2;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<2;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<2;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<2;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<5;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<8;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<7;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<7;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<5;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<4;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
for(n=0;n<3;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
if(++index==20)
{
index=0;
}
//----------------
//for(n=0;n<1;n++)
{
WS2811_SendByte(Design2[index].r);
WS2811_SendByte(Design2[index].b);
WS2811_SendByte(Design2[index].g);
}
}
IO_DIN=1;
IO_DIN=0;
while(k--)
{
_nop_();
}
}
ucharc SPEED1[]={10,8, 6, 4,2,0};
ucharc SPEED[]= {20,15,10,6,2,0};
void main(void)
{
int ind=19;
uchar cnt;
Init_Data(); // 初始化各种端口和数据
while(1)
{
#if 1
/*
1、从左往右扫
2、从右往左扫
3、从中间向两边扫
4、从两边向中间扫
*/
for(cnt=0;cnt<3;cnt++)
{
for(ind=0;ind<110;ind++)
{
WS2811_Setout2(ind);
DelayN10ms(SPEED1[gSpeed]);
}
}
for(cnt=0;cnt<3;cnt++)
{
for(ind=109;ind>=0;ind--)
{
WS2811_Setout2(ind);
DelayN10ms(SPEED1[gSpeed]);
}
}
//33333333333
for(cnt=0;cnt<3;cnt++)
{ //3.从55-110-1-54扫描
for(ind=55;ind<110;ind++)
{
WS2811_Setout2(ind);
DelayN10ms(SPEED1[gSpeed]);
}
for(ind=0;ind<55;ind++)
{
WS2811_Setout2(ind);
DelayN10ms(SPEED1[gSpeed]);
}
}
//444444444444444
for(cnt=0;cnt<3;cnt++)
{ //4.从54-1-110-55扫描
for(ind=54;ind>=0;ind--)
{
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
0.png
(42.84 KB, 下载次数: 115)
下载附件
2017-3-15 04:35 上传
0.png
(60.07 KB, 下载次数: 128)
下载附件
2017-3-15 04:35 上传
源码下载:
WS2811_LEDs.zip.7z
(37.95 KB, 下载次数: 305)
2022-4-23 16:01 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
faridzled
时间:
2017-1-4 21:22
Thanks for sharing, i like it
作者:
quest_smt
时间:
2017-5-4 22:30
刚好需要,正在学单片机呢。谢谢分享
作者:
_少年放肆的梦
时间:
2017-5-4 23:13
谢谢分享
作者:
yokochristina
时间:
2017-6-8 15:14
谢谢楼主
作者:
zhengen
时间:
2017-6-17 12:18
交流一下好嘛
作者:
zhengen
时间:
2017-6-17 12:39
黑币不够,非常想下载这个资源,求通过
作者:
b2329164
时间:
2017-9-7 14:26
謝大大分享 剛好正在使用
作者:
yerdong
时间:
2017-11-23 16:50
LZ是用的,延时的方式还是PWM输出的方式控制?
作者:
简近树
时间:
2017-12-17 19:21
可以很强
作者:
mch205
时间:
2018-3-8 10:32
开始学习了
作者:
baishifanzon
时间:
2018-4-18 13:43
好好学习一下,感谢楼主无私的分享!
作者:
101113b
时间:
2018-4-23 13:36
给力,下载看看
作者:
101113b
时间:
2018-4-23 13:38
学习一下感谢楼主无私的分享!
作者:
21cnxin
时间:
2018-6-29 14:56
学习一下感谢楼主无私的分享!
作者:
only画地为牢
时间:
2019-7-4 20:09
正在学习这个IC的用法 赞一个!
作者:
夕日东
时间:
2020-3-29 23:27
Thanks for sharing, i like it
作者:
huihuangzeng
时间:
2023-9-18 22:59
谢谢坛主。学习了。
作者:
wkman
时间:
2023-9-19 14:00
一路多少颗灯珠?
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1