百变闪字棒
【简介】你见过会显示日期及温度的自行车吗?你有听过POV LED吗?这个项目中,做一个百变闪字棒,模拟这种自行车的效果。最后完成图如下
【器材】Arduino Nano,LED×15,震动传感器,面包板,导线若干。
【原理】电路原理图如下
【接线】接线示意图如下
【程序】代码程序如下
int a = 12;// LED1接digital_12
int b = 10;// LED2接digital_10
int c = 8;//LED3接digital_8
int d = 6;//LED4接digital_6
int e = 4;//LED5接digital_4
int f = 2;//LED6接digital_2
int g = 0;//LED7接digital_0
int h = 1;//LED8接digital_1
int j = 13;// LED9接digital_13
int k = 19;// LED10接analog_A5 (模拟口A0-A5相当于数据口digital14-digial19)
int m = 18;// LED11接analog_A4
int n = 17;// LED12接analog_A3
int p = 16;// LED13接analog_A2
int q = 15;// LED14接analog_A1
int r = 14;// LED15接analog_A0
//震动开关触发后,延迟时间的调整,采用触发后300+50=350毫秒以保持同步
int delayTime1=300;
//采用矩阵输出字符图形,每个字符高15个点
byte bars = {a,b,c,d,e,f,g,h,j,k,m,n,p,q,r};
/***************************字模数组******************************/
byte youth_digits = {//---显示‘少年’的数组
{0,0,0,0,0,0,0,1,1,0,0,0,0,0,1 },//少
{0,0,0,0,0,0,1,1,0,0,0,0,0,0,1 },
{0,0,0,0,1,1,1,0,0,0,0,0,0,0,1 },
{0,0,0,0,1,0,0,0,0,0,0,0,0,1,1 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
{1,1,1,1,1,1,1,1,1,1,0,0,1,1,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 },
{0,0,0,1,0,0,0,0,0,0,0,1,0,0,0 },
{0,0,0,0,1,0,0,0,0,0,1,1,0,0,0 },
{0,0,0,0,1,1,0,0,0,1,1,0,0,0,0 },
{0,0,0,0,0,1,1,0,0,1,0,0,0,0,0 },
{0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
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0,0,0,0,0,1 },
{0,1,0,0,0,1,0,0,1,0,0,0,0,0,1 },
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
{0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
{1,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
{1,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
{1,0,0,0,0,1,0,0,1,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,1,0,0,0,0,0,0 },};
/***************************初始化函数******************************/
void setup()//设置输出口
{
for (int i = 0; i < 3; i++)
{
pinMode(i, OUTPUT); //设置D0到D2引脚为输出状态
digitalWrite(i,LOW);//初始设置,所有的LED灭
}
pinMode(3, INPUT); //设置D3引脚为输入状态,为震动开关的数字输入
digitalWrite(3,HIGH);//初始设置内置上拉电阻:20-50k
for (int i = 4; i < 20; i++)
{
pinMode(i, OUTPUT); //设置D4到D19引脚为输出状态
digitalWrite(i,LOW);//初始设置,所有的LED灭
}
}
/***************子函数(显示“少年电子高手”)字样函数******************/
void youth() //---------------- 点亮‘少年’字样
{
for (int j=0;j<28;j++)
{
//第一重循环,横扫‘少年’两个字的列,每个字14列
for (int i = 0; i < 15; i++)
{
//第二重循环,竖扫15次,逐个给一列当中的每一个点赋值
//对应数组依次点亮每个灯来显示少年字样
digitalWrite(bars,youth_digits );
}
delay(3);//这个延迟时间很重要,关系到摇动的快慢以及字的宽度
}
for (int kk = 0; kk <20; kk++)
{
digitalWrite(kk,LOW);//所有灯熄灭
}
}
void electronic()//------------ 点亮‘电子’字样
{
for (int j=0;j<26;j++){
//第一重循环,横扫‘电子’两个字的列,共26列
for (int i = 0; i < 15; i++)
{
//第二重循环,竖扫15次,逐个给一列当中的每一个点赋值
//对应数组依次点亮每个灯来显示电子字样
digitalWrite(bars,dianzi_digits );
}
delay(3); //这个延迟时间很重要,关系到摇动的快慢以及字的宽度
}
for (int kk = 0; kk <20; kk++)
{
digitalWrite(kk,LOW); //所有灯熄灭
}
}
void gaoshou()//--------------- 点亮‘高手’字样
{
for (int j=0;j<15;j++)
{ // 点亮‘高’
for (int i = 0; i < 15; i++)
{
digitalWrite(bars,gao_digits );
}
delay(3);
}
for (int kk = 0; kk <20; kk++)
{
digitalWrite(kk,LOW);
}
for (int j=0;j<14;j++)// 点亮‘手’,与上面的高组成词:高手
{
for (int i = 0; i < 15; i++)
{
digitalWrite(bars,shou_digits );
}
delay(3);
}
for (int kk = 0; kk <20; kk++)
{
digitalWrite(kk,LOW);
}
}
/***************************主函数******************************/
void loop()
{
while(1)//采用震动开关触发,等待手摇棒触发
{
if (digitalRead(3)==0)
{
delay(50); //延时,防抖动
//当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
if (digitalRead(3)==0)
break;
}
}
delay(delayTime1); //触发后延时,基本上做到了同步
youth(); //显示‘少年’字样
digitalWrite(3,HIGH);//把D3口写高,等待下一次手摇触发
//*******************************************************************
while(1) //采用震动开关触发,等待手摇棒触发
{
if (digitalRead(3)==0)
{
delay(50);
//当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
if (digitalRead(3)==0)
break;
}
}
delay(delayTime1); //触发后延时,基本上做到了同步
electronic(); //显示‘电子’字样
digitalWrite(3,HIGH); //把D3口写高,等待下一次手摇触发
//*******************************************************************
while(1) //采用震动开关触发,等待手摇棒触发
{
if (digitalRead(3)==0)
{
delay(50);
//当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
if (digitalRead(3)==0)
break;
}
}
delay(delayTime1); //触发后延时,基本上做到了同步
gaoshou(); //显示‘高手’字样
digitalWrite(3,HIGH); //把D3口写高,等待下一次手摇触发
}
luna 发表于 2015-10-28 12:12
棒棒哒~可以再详细一点吗?我想把这一篇发微信发微信~~
{:5_178:}这已经够详细的了吧,闪字棒发微信是不是小题大做了,可以找位大虾做出自行车,这样发微信看起来就好 丄帝De咗臂 发表于 2015-10-29 13:58
可以把字的程序作为子程序,在主程序中调用不同的子程序,不久改字了
大神我是小白能否再详细点,比如做个例子我看看,最好详细到每一步 这个开出去不是很拉风? dsweiliang 发表于 2015-10-28 11:02
这个开出去不是很拉风?
相当拉轰 丄帝De咗臂 发表于 2015-10-28 11:58
相当拉轰
显示什么会觉得更拉风呢? 是你自己做的吗? luna 发表于 2015-10-28 12:01
是你自己做的吗?
闪字棒是我做的,自行车不是{:5_195:} dsweiliang 发表于 2015-10-28 12:01
显示什么会觉得更拉风呢?
打倒美帝{:5_191:} 丄帝De咗臂 发表于 2015-10-28 12:06
闪字棒是我做的,自行车不是
棒棒哒~可以再详细一点吗?我想把这一篇发微信发微信~~ 丄帝De咗臂 发表于 2015-10-28 12:20
这已经够详细的了吧,闪字棒发微信是不是小题大做了,可以找位大虾做出自行车,这样发微信看起 ...
配上我在自行车吧。虎虎 丄帝De咗臂 发表于 2015-10-28 12:20
这已经够详细的了吧,闪字棒发微信是不是小题大做了,可以找位大虾做出自行车,这样发微信看起 ...
具体怎么安装呢? 丄帝De咗臂 发表于 2015-10-28 12:07
打倒美帝
收买烂铜烂铁,这个也不错啊 收破烂能加上去吗{:5_172:} 大连林海 发表于 2015-10-29 07:49
收破烂能加上去吗
收废品 丄帝De咗臂 发表于 2015-10-29 08:18
收废品
怎么安装
{:5_129:} hnyzcj 发表于 2015-10-29 11:01
怎么安装
把板子放在最中间
线放到管子里,与辐条一起 丄帝De咗臂 发表于 2015-10-29 13:51
把板子放在最中间
线放到管子里,与辐条一起
晕,我是问你灯的排列,就一条直线排着吗 丄帝De咗臂 发表于 2015-10-29 13:51
把板子放在最中间
线放到管子里,与辐条一起
另外字怎么改 hnyzcj 发表于 2015-10-29 13:54
另外字怎么改
可以把字的程序作为子程序,在主程序中调用不同的子程序,不久改字了
丄帝De咗臂 发表于 2015-10-29 08:18
收废品
把张大师加上去
页:
[1]
2