[项目]百变闪字棒

27148浏览
查看: 27148|回复: 34

[项目] 百变闪字棒

[复制链接]
【简介】你见过会显示日期及温度的自行车吗?你有听过POV LED吗?百变闪字棒图1
这个项目中,做一个百变闪字棒,模拟这种自行车的效果。最后完成图如下
百变闪字棒图2


【器材】Arduino Nano,LED×15,震动传感器,面包板,导线若干。
【原理】电路原理图如下


百变闪字棒图3

【接线】接线示意图如下
百变闪字棒图4

【程序】代码程序如下
  1. int a = 12;// LED1接digital_12
  2. int b = 10;// LED2接digital_10
  3. int c = 8;//  LED3接digital_8
  4. int d = 6;//  LED4接digital_6
  5. int e = 4;//  LED5接digital_4
  6. int f = 2;//  LED6接digital_2
  7. int g = 0;//  LED7接digital_0
  8. int h = 1;//  LED8接digital_1
  9. int j = 13;// LED9接digital_13
  10. int k = 19;// LED10接analog_A5 (模拟口A0-A5相当于数据口digital14-digial19)
  11. int m = 18;// LED11接analog_A4
  12. int n = 17;// LED12接analog_A3
  13. int p = 16;// LED13接analog_A2
  14. int q = 15;// LED14接analog_A1
  15. int r = 14;// LED15接analog_A0
  16. //震动开关触发后,延迟时间的调整,采用触发后300+50=350毫秒以保持同步
  17. int delayTime1=300;
  18. //采用矩阵输出字符图形,每个字符高15个点
  19. byte bars[15] = {a,b,c,d,e,f,g,h,j,k,m,n,p,q,r};
  20. /***************************字模数组******************************/
  21. byte youth_digits[28][15] = {  //---显示‘少年’的数组
  22. {0,0,0,0,0,0,0,1,1,0,0,0,0,0,1 },//少
  23. {0,0,0,0,0,0,1,1,0,0,0,0,0,0,1 },
  24. {0,0,0,0,1,1,1,0,0,0,0,0,0,0,1 },
  25. {0,0,0,0,1,0,0,0,0,0,0,0,0,1,1 },
  26. {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
  27. {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 },
  28. {1,1,1,1,1,1,1,1,1,1,0,0,1,1,0 },
  29. {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0 },
  30. {0,0,0,1,0,0,0,0,0,0,0,1,0,0,0 },
  31. {0,0,0,0,1,0,0,0,0,0,1,1,0,0,0 },
  32. {0,0,0,0,1,1,0,0,0,1,1,0,0,0,0 },
  33. {0,0,0,0,0,1,1,0,0,1,0,0,0,0,0 },
  34. {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 },
  35. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  36. {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },//年
  37. {0,0,0,0,0,1,0,0,0,0,1,0,0,0,0 },
  38. {0,0,1,1,1,0,1,1,1,1,1,0,0,0,0 },
  39. {1,1,1,1,0,0,1,0,0,0,1,0,0,0,0 },
  40. {0,0,0,1,0,0,1,0,0,0,1,0,0,0,0 },
  41. {0,0,0,1,0,0,1,0,0,0,1,0,0,0,0 },
  42. {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1 },
  43. {0,0,0,1,0,0,1,0,0,0,1,0,0,0,0 },
  44. {0,0,0,1,0,0,1,0,0,0,1,0,0,0,0 },
  45. {0,0,0,1,0,0,1,0,0,0,1,0,0,0,0 },
  46. {0,0,0,1,0,0,1,0,0,0,1,0,0,0,0 },
  47. {0,0,0,1,0,0,0,0,0,0,1,0,0,0,0 },
  48. {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },};
  49. byte dianzi_digits[26][15] = { //--- 显示‘电子’的数组
  50. {0,0,0,1,1,1,1,1,1,1,1,1,0,0,0 },//电
  51. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,0 },
  52. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,0 },
  53. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,0 },
  54. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,0 },
  55. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,0 },
  56. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,1 },
  57. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,1 },
  58. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,1 },
  59. {0,0,0,1,0,0,0,1,0,0,1,0,0,0,1 },
  60. {0,0,0,1,1,1,1,1,1,1,1,0,0,1,0 },
  61. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  62. {0,0,0,0,0,0,1,0,0,0,1,0,0,0,0 },//子
  63. {0,0,0,0,0,0,1,0,0,0,1,0,0,0,0 },
  64. {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0 },
  65. {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0 },
  66. {1,0,0,0,0,0,1,0,0,0,0,0,0,1,0 },
  67. {1,0,0,0,0,0,1,0,0,0,0,0,0,1,0 },
  68. {1,0,0,1,1,1,1,1,1,1,1,1,1,1,0 },
  69. {1,0,0,1,0,0,1,0,0,0,0,0,0,0,0 },
  70. {1,0,1,0,0,0,1,0,0,0,0,0,0,0,0 },
  71. {1,1,1,0,0,0,1,0,0,0,0,0,0,0,0 },
  72. {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0 },
  73. {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0 },
  74. {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0 },
  75. {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0 }, };
  76. byte gao_digits[15][15] = {    //--- 显示‘高’的数组
  77. {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  78. {0,1,0,0,0,0,0,0,0,1,1,1,1,1,1 },
  79. {0,1,0,0,0,0,0,0,1,0,0,0,0,0,0 },
  80. {0,1,0,1,1,1,1,0,1,0,0,0,0,0,0 },
  81. {0,1,0,1,0,0,1,0,1,0,1,1,1,0,0 },
  82. {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
  83. {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
  84. {1,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
  85. {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
  86. {0,1,0,1,0,0,1,0,1,0,1,0,1,0,0 },
  87. {0,1,0,1,0,0,1,0,1,0,1,1,1,0,0 },
  88. {0,1,0,1,1,1,1,0,1,0,0,0,0,0,0 },
  89. {0,1,0,0,0,0,0,0,1,0,0,0,0,0,1 },
  90. {0,1,0,0,0,0,0,0,0,1,1,1,1,1,1 },
  91. {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },};
  92. byte shou_digits[14][15] = {   //--- 显示‘手’的数组
  93. {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0 },
  94. {0,1,0,0,0,0,0,0,1,0,0,0,0,0,0 },
  95. {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  96. {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  97. {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  98. {0,1,0,0,0,1,0,0,1,0,0,0,0,0,1 },
  99. {0,1,0,0,0,1,0,0,1,0,0,0,0,0,1 },
  100. {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
  101. {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  102. {0,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  103. {1,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  104. {1,1,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  105. {1,0,0,0,0,1,0,0,1,0,0,0,0,0,0 },
  106. {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0 },};
  107. /***************************初始化函数******************************/
  108. void setup()//设置输出口
  109. {
  110.   for (int i = 0; i < 3; i++)
  111. {
  112.    pinMode(i, OUTPUT); //设置D0到D2引脚为输出状态
  113.    digitalWrite(i,LOW);//初始设置,所有的LED灭
  114. }
  115.   pinMode(3, INPUT);   //设置D3引脚为输入状态,为震动开关的数字输入
  116.    digitalWrite(3,HIGH);//初始设置内置上拉电阻:20-50k
  117. for (int i = 4; i < 20; i++)
  118. {
  119.    pinMode(i, OUTPUT); //设置D4到D19引脚为输出状态
  120.    digitalWrite(i,LOW);//初始设置,所有的LED灭
  121. }
  122. }
  123. /***************子函数(显示“少年电子高手”)字样函数******************/
  124. void youth() //---------------- 点亮‘少年’字样
  125. {
  126. for (int j=0;j<28;j++)
  127. {
  128. //第一重循环,横扫‘少年’两个字的列,每个字14列
  129. for (int i = 0; i < 15; i++)
  130. {
  131. //第二重循环,竖扫15次,逐个给一列当中的每一个点赋值
  132. //对应数组依次点亮每个灯来显示少年字样
  133.           digitalWrite(bars[i],youth_digits[j][i] );      
  134. }
  135.    delay(3);//这个延迟时间很重要,关系到摇动的快慢以及字的宽度
  136. }
  137. for (int kk = 0; kk <20; kk++)
  138. {
  139.     digitalWrite(kk,LOW);//所有灯熄灭
  140.   }
  141. }
  142. void electronic()//------------ 点亮‘电子’字样
  143. {
  144.   for (int j=0;j<26;j++){
  145.   //第一重循环,横扫‘电子’两个字的列,共26列
  146.    for (int i = 0; i < 15; i++)
  147. {
  148. //第二重循环,竖扫15次,逐个给一列当中的每一个点赋值
  149.           //对应数组依次点亮每个灯来显示电子字样
  150. digitalWrite(bars[i],dianzi_digits[j][i] );      
  151. }
  152.    delay(3); //这个延迟时间很重要,关系到摇动的快慢以及字的宽度
  153. }
  154.   for (int kk = 0; kk <20; kk++)
  155. {
  156.     digitalWrite(kk,LOW); //所有灯熄灭
  157.    }
  158. }
  159. void gaoshou()//--------------- 点亮‘高手’字样
  160. {
  161.    for (int j=0;j<15;j++)
  162. { // 点亮‘高’
  163.       for (int i = 0; i < 15; i++)
  164. {
  165.         digitalWrite(bars[i],gao_digits[j][i] );      
  166. }
  167.       delay(3);
  168.     }
  169.    for (int kk = 0; kk <20; kk++)
  170. {
  171.     digitalWrite(kk,LOW);
  172.    }
  173.   for (int j=0;j<14;j++)// 点亮‘手’,与上面的高组成词:高手
  174. {
  175.      for (int i = 0; i < 15; i++)
  176. {
  177.        digitalWrite(bars[i],shou_digits[j][i] );      
  178. }
  179.      delay(3);
  180.    }
  181.   for (int kk = 0; kk <20; kk++)
  182. {
  183.     digitalWrite(kk,LOW);
  184.   }
  185. }
  186. /***************************主函数******************************/
  187. void loop()
  188. {
  189.   while(1)//采用震动开关触发,等待手摇棒触发
  190.   {
  191.     if (digitalRead(3)==0)
  192.     {
  193. delay(50); //延时,防抖动
  194. //当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
  195.       if (digitalRead(3)==0)
  196. break;
  197.     }
  198.   }
  199. delay(delayTime1);   //触发后延时,基本上做到了同步
  200. youth();              //显示‘少年’字样
  201. digitalWrite(3,HIGH);//把D3口写高,等待下一次手摇触发
  202. //*******************************************************************
  203. while(1) //采用震动开关触发,等待手摇棒触发
  204. {
  205.     if (digitalRead(3)==0)
  206.     {
  207. delay(50);
  208. //当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
  209.       if (digitalRead(3)==0)
  210. break;
  211.   }
  212. }
  213. delay(delayTime1);    //触发后延时,基本上做到了同步
  214. electronic();         //显示‘电子’字样
  215. digitalWrite(3,HIGH); //把D3口写高,等待下一次手摇触发
  216. //*******************************************************************
  217. while(1) //采用震动开关触发,等待手摇棒触发
  218. {
  219.     if (digitalRead(3)==0)
  220.     {
  221. delay(50);
  222. //当手摇使得震动开关闭合,在D3口读震动开关数据,低电平则跳出死循环
  223.       if (digitalRead(3)==0)
  224. break;
  225.   }
  226. }
  227. delay(delayTime1);    //触发后延时,基本上做到了同步
  228. gaoshou();            //显示‘高手’字样
  229. digitalWrite(3,HIGH); //把D3口写高,等待下一次手摇触发
  230. }
复制代码



丄帝De咗臂  高级技匠
 楼主|

发表于 2015-10-28 12:20:47

luna 发表于 2015-10-28 12:12
棒棒哒~可以再详细一点吗?我想把这一篇发微信发微信~~

这已经够详细的了吧,闪字棒发微信是不是小题大做了,可以找位大虾做出自行车,这样发微信看起来就好
回复

使用道具 举报

hnyzcj  版主

发表于 2015-10-29 16:00:39

丄帝De咗臂 发表于 2015-10-29 13:58
可以把字的程序作为子程序,在主程序中调用不同的子程序,不久改字了

大神我是小白能否再详细点,比如做个例子我看看,最好详细到每一步
回复

使用道具 举报

dsweiliang  初级技神

发表于 2015-10-28 11:02:57

这个开出去不是很拉风?
回复

使用道具 举报

丄帝De咗臂  高级技匠
 楼主|

发表于 2015-10-28 11:58:21

dsweiliang 发表于 2015-10-28 11:02
这个开出去不是很拉风?

相当拉轰
回复

使用道具 举报

dsweiliang  初级技神

发表于 2015-10-28 12:01:24


显示什么会觉得更拉风呢?
回复

使用道具 举报

luna  初级技神

发表于 2015-10-28 12:01:40

是你自己做的吗?
回复

使用道具 举报

丄帝De咗臂  高级技匠
 楼主|

发表于 2015-10-28 12:06:11

luna 发表于 2015-10-28 12:01
是你自己做的吗?

闪字棒是我做的,自行车不是
回复

使用道具 举报

丄帝De咗臂  高级技匠
 楼主|

发表于 2015-10-28 12:07:14

dsweiliang 发表于 2015-10-28 12:01
显示什么会觉得更拉风呢?

打倒美帝
回复

使用道具 举报

luna  初级技神

发表于 2015-10-28 12:12:06

丄帝De咗臂 发表于 2015-10-28 12:06
闪字棒是我做的,自行车不是

棒棒哒~可以再详细一点吗?我想把这一篇发微信发微信~~
回复

使用道具 举报

hnyzcj  版主

发表于 2015-10-28 13:31:26

丄帝De咗臂 发表于 2015-10-28 12:20
这已经够详细的了吧,闪字棒发微信是不是小题大做了,可以找位大虾做出自行车,这样发微信看起 ...

配上我在自行车吧。虎虎
回复

使用道具 举报

hnyzcj  版主

发表于 2015-10-28 13:33:18

丄帝De咗臂 发表于 2015-10-28 12:20
这已经够详细的了吧,闪字棒发微信是不是小题大做了,可以找位大虾做出自行车,这样发微信看起 ...

具体怎么安装呢?
回复

使用道具 举报

dsweiliang  初级技神

发表于 2015-10-28 13:45:56


收买烂铜烂铁,这个也不错啊
回复

使用道具 举报

大连林海  初级技神

发表于 2015-10-29 07:49:28

收破烂能加上去吗
回复

使用道具 举报

丄帝De咗臂  高级技匠
 楼主|

发表于 2015-10-29 08:18:14


收废品
回复

使用道具 举报

hnyzcj  版主

发表于 2015-10-29 11:01:43

回复

使用道具 举报

丄帝De咗臂  高级技匠
 楼主|

发表于 2015-10-29 13:51:11


把板子放在最中间
线放到管子里,与辐条一起
回复

使用道具 举报

hnyzcj  版主

发表于 2015-10-29 13:53:55

丄帝De咗臂 发表于 2015-10-29 13:51
把板子放在最中间
线放到管子里,与辐条一起

晕,我是问你灯的排列,就一条直线排着吗
回复

使用道具 举报

hnyzcj  版主

发表于 2015-10-29 13:54:37

丄帝De咗臂 发表于 2015-10-29 13:51
把板子放在最中间
线放到管子里,与辐条一起

另外字怎么改
回复

使用道具 举报

丄帝De咗臂  高级技匠
 楼主|

发表于 2015-10-29 13:58:19


可以把字的程序作为子程序,在主程序中调用不同的子程序,不久改字了
回复

使用道具 举报

大连林海  初级技神

发表于 2015-10-29 19:04:27


把张大师加上去
回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail