arduino 微信红包怎么免费领取机器人爱好者之家

?找回密码
?立即注册

QQ登录

只需一步,快速开始

查看: 501|回复: 0
打印 上一主题 下一主题

这是追求极致还是死磕?

[复制链接]

该用户从未签到

跳转到指定楼层
楼主
发表于 2019-6-2 10:07:32 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
2019-5-15版本一:https://www.bilibili.com/video/av52557415/


2019-6-2版本二:https://www.bilibili.com/video/av54323283/



废话不多说,源码如下
  1. /*
  2. 2019 ? Arduino_Maker
  3. */
  4. #include

  5. byte m = 0;? ?
  6. byte Pvalue = 0;? ?? ?? ?? ?
  7. boolean BreatheFlag = true;? ?
  8. byte ModeNumber = 0;? ?? ?? ?
  9. //byte oldModeNumber = 0;? ?? ?
  10. boolean Touchflag = false;? ?
  11. unsigned int Time1 = 0;? ?? ?
  12. unsigned int timex = 0;? ?? ?

  13. const byte Ring[5][6]={
  14. ? ?? ?? ?? ?? ? {2,19,13},? ?? ???
  15. ? ?? ?? ?? ?? ? {9,14,17},? ?? ???
  16. ? ?? ?? ?? ?? ? {4,8,15,6,10,7},
  17. ? ?? ?? ?? ?? ? {18,16,12},? ?? ?
  18. ? ?? ?? ?? ?? ? {11,5,3}? ?? ?? ?
  19. ? ?? ?? ?? ?? ? };

  20. void setup() {
  21. ??Serial.begin(9600);
  22. ??for(int i=0;i<5;i++){
  23. ? ? for(int j=0;Ring[i][j]!='\0';j++){
  24. ? ?? ?pinMode(Ring[i][j],OUTPUT);
  25. ? ? }
  26. ??}
  27. ??Timer1.initialize( 100000 );
  28. ??Timer1.attachInterrupt( Timer2Interrupt );
  29. }

  30. void Timer2Interrupt(void){
  31. ??if((analogRead(A6) < 100)??&& (Touchflag==false)){
  32. ? ? Touchflag = true;
  33. ? ? Time1 = millis();
  34. ? ? ModeNumber = ModeNumber + 1;
  35. ? ? if(ModeNumber == 2) m = 0;
  36. ? ? if(ModeNumber == 7) ModeNumber = 0;
  37. ? ? //Serial.println(ModeNumber);
  38. ? ? }
  39. ? ? else??if((analogRead(A6) > 100)??&& (Touchflag==true)){
  40. ? ?? ?Touchflag = false;
  41. ? ?? ?timex = millis() - Time1;
  42. ? ?? ?if(timex > 3000)??ModeNumber = 0;
  43. ? ?? ?}
  44. ??}

  45. void loop() {

  46. ??switch(ModeNumber){
  47. ? ? case 0:? ?Mode0();? ?? ?break;
  48. ? ? case 1:? ?Mode1(10);? ? break;
  49. ? ? case 2:? ?Mode2(100);? ?break;
  50. ? ? case 3:? ?Mode3(100);? ?break;
  51. ? ? case 4:? ?Mode4(100);? ?break;
  52. ? ? case 5:? ?Mode5(10);? ? break;
  53. ? ? case 6:? ?Mode6(60);? ? break;
  54. ? ? default:??break;
  55. ? ? }
  56. }

  57. void Mode0(void)
  58. {
  59. ??Ring_Run(0,false);
  60. ??Ring_Run(1,false);
  61. ??Ring_Run(2,false);
  62. ??Ring_Run(3,false);
  63. ??Ring_Run(4,false);
  64. ??}
  65. void Mode1(int Mytime)
  66. {
  67. ??analogWrite(Ring[4][0],Pvalue);
  68. ??analogWrite(Ring[4][1],Pvalue);
  69. ??analogWrite(Ring[4][2],Pvalue);
  70. ??if(BreatheFlag==true){
  71. ? ? Pvalue = Pvalue + 1;
  72. ? ? if(Pvalue == 255) BreatheFlag = false;
  73. ? ? }
  74. ??if(BreatheFlag==false){
  75. ? ? Pvalue = Pvalue - 1;
  76. ? ? if(Pvalue == 0) BreatheFlag = true;
  77. ? ? }
  78. ??delay(Mytime);
  79. ??}
  80. void Mode2(int Mytime)
  81. {
  82. ??switch(m){
  83. ? ? case 0:? ?Ring_Run(0,true); break;
  84. ? ? case 1:? ?delay(4*Mytime);??break;
  85. ? ? case 2:? ?Ring_Run(1,true); break;
  86. ? ? case 3:? ?delay(3*Mytime);??break;
  87. ? ? case 4:? ?Ring_Run(2,true); break;
  88. ? ? case 5:? ?delay(2*Mytime);??break;
  89. ? ? case 6:? ?Ring_Run(3,true); break;
  90. ? ? case 7:? ?delay(Mytime);? ? break;
  91. ? ? case 8:? ?Ring_Run(4,true); break;
  92. ? ? case 9:? ?delay(4*Mytime);??break;
  93. ? ? case 10:??delay(4*Mytime);??break;
  94. ? ? case 11:??Ring_Run(4,false);break;
  95. ? ? case 12:??delay(Mytime);? ? break;
  96. ? ? case 13:??Ring_Run(3,false);break;
  97. ? ? case 14:??delay(2*Mytime);??break;
  98. ? ? case 15:??Ring_Run(2,false);break;
  99. ? ? case 16:??delay(3*Mytime);??break;
  100. ? ? case 17:??Ring_Run(1,false);break;
  101. ? ? case 18:??delay(4*Mytime);??break;
  102. ? ? case 19:??Ring_Run(0,false);break;
  103. ? ? case 20:??delay(4*Mytime);??break;
  104. ? ? case 21:??delay(4*Mytime);??break;
  105. ? ? default: break;
  106. ? ? }
  107. ? ? m = m + 1;
  108. ? ? if(m == 22) m = 0;
  109. ??}
  110. void Mode3(int Mytime)
  111. {
  112. ??Ring_Run(0,true);
  113. ??Ring_Run(1,true);
  114. ??Ring_Run(2,true);
  115. ??Ring_Run(3,true);
  116. ??Ring_Run(4,true);
  117. ??delay(Mytime);
  118. ??Ring_Run(0,false);
  119. ??Ring_Run(1,false);
  120. ??Ring_Run(2,false);
  121. ??Ring_Run(3,false);
  122. ??Ring_Run(4,false);
  123. ??delay(Mytime);
  124. ??}
  125. void Mode4(int Mytime)
  126. {
  127. ??Leaf_Run(2,false);Leaf_Run(0,true);delay(Mytime);
  128. ??Leaf_Run(0,false);Leaf_Run(1,true);delay(Mytime);
  129. ??Leaf_Run(1,false);Leaf_Run(2,true);delay(Mytime);??
  130. ??}
  131. void Mode5(int Mytime)
  132. {
  133. ??digitalWrite(Ring[0][2],LOW);digitalWrite(Ring[0][0],HIGH);delay(Mytime);
  134. ??digitalWrite(Ring[0][0],LOW);digitalWrite(Ring[0][1],HIGH);delay(Mytime);
  135. ??digitalWrite(Ring[0][1],LOW);digitalWrite(Ring[0][2],HIGH);delay(Mytime);
  136. ??digitalWrite(Ring[0][2],LOW);
  137. ??digitalWrite(Ring[1][1],LOW);digitalWrite(Ring[1][0],HIGH);delay(Mytime);
  138. ??digitalWrite(Ring[1][0],LOW);digitalWrite(Ring[1][2],HIGH);delay(Mytime);
  139. ??digitalWrite(Ring[1][2],LOW);digitalWrite(Ring[1][1],HIGH);delay(Mytime);??
  140. ??digitalWrite(Ring[1][1],LOW);
  141. ??digitalWrite(Ring[2][4],LOW);digitalWrite(Ring[2][5],LOW);digitalWrite(Ring[2][2],HIGH);digitalWrite(Ring[2][3],HIGH);delay(Mytime);
  142. ??digitalWrite(Ring[2][2],LOW);digitalWrite(Ring[2][3],LOW);digitalWrite(Ring[2][0],HIGH);digitalWrite(Ring[2][1],HIGH);delay(Mytime);
  143. ??digitalWrite(Ring[2][0],LOW);digitalWrite(Ring[2][1],LOW);digitalWrite(Ring[2][4],HIGH);digitalWrite(Ring[2][5],HIGH);delay(Mytime);
  144. ??digitalWrite(Ring[2][4],LOW);digitalWrite(Ring[2][5],LOW);
  145. ??digitalWrite(Ring[3][2],LOW);digitalWrite(Ring[3][0],HIGH);delay(Mytime);
  146. ??digitalWrite(Ring[3][0],LOW);digitalWrite(Ring[3][1],HIGH);delay(Mytime);
  147. ??digitalWrite(Ring[3][1],LOW);digitalWrite(Ring[3][2],HIGH);delay(Mytime);
  148. ??digitalWrite(Ring[3][2],LOW);
  149. ??digitalWrite(Ring[4][2],LOW);digitalWrite(Ring[4][0],HIGH);delay(Mytime);
  150. ??digitalWrite(Ring[4][0],LOW);digitalWrite(Ring[4][1],HIGH);delay(Mytime);
  151. ??digitalWrite(Ring[4][1],LOW);digitalWrite(Ring[4][2],HIGH);delay(Mytime);
  152. ??digitalWrite(Ring[4][2],LOW);
  153. ??}
  154. void Mode6(int Mytime)
  155. {
  156. ??Ring_Run(0,true);
  157. ??Ring_Run(4,true);
  158. ??digitalWrite(Ring[2][4],LOW);digitalWrite(Ring[2][3],HIGH);delay(Mytime);
  159. ??digitalWrite(Ring[2][3],LOW);digitalWrite(Ring[3][1],HIGH);delay(Mytime);
  160. ??digitalWrite(Ring[3][1],LOW);digitalWrite(Ring[2][2],HIGH);delay(Mytime);
  161. ??digitalWrite(Ring[2][2],LOW);digitalWrite(Ring[2][1],HIGH);delay(Mytime);
  162. ??digitalWrite(Ring[2][1],LOW);digitalWrite(Ring[3][0],HIGH);delay(Mytime);
  163. ??digitalWrite(Ring[3][0],LOW);digitalWrite(Ring[2][0],HIGH);delay(Mytime);
  164. ??digitalWrite(Ring[2][0],LOW);digitalWrite(Ring[2][5],HIGH);delay(Mytime);
  165. ??digitalWrite(Ring[2][5],LOW);digitalWrite(Ring[3][2],HIGH);delay(Mytime);
  166. ??digitalWrite(Ring[3][2],LOW);digitalWrite(Ring[2][4],HIGH);delay(Mytime);

  167. ??}
  168. void Ring_Run(byte n,boolean k)
  169. {
  170. ??if(k==true)
  171. ? ? switch(n){
  172. ? ?? ?case 0:
  173. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[0][i],HIGH);??break;
  174. ? ?? ?case 1:
  175. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[1][i],HIGH);??break;
  176. ? ?? ?case 2:
  177. ? ?? ???for(int i = 0;i < 6;i++)??digitalWrite(Ring[2][i],HIGH);??break;
  178. ? ?? ?case 3:
  179. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[3][i],HIGH);??break;
  180. ? ?? ?case 4:
  181. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[4][i],HIGH);??break;
  182. ? ?? ?default : break;
  183. ? ?? ?}
  184. ? ? else??switch(n){
  185. ? ?? ?case 0:
  186. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[0][i],LOW);??break;
  187. ? ?? ?case 1:
  188. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[1][i],LOW);??break;
  189. ? ?? ?case 2:
  190. ? ?? ???for(int i = 0;i < 6;i++)??digitalWrite(Ring[2][i],LOW);??break;
  191. ? ?? ?case 3:
  192. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[3][i],LOW);??break;
  193. ? ?? ?case 4:
  194. ? ?? ???for(int i = 0;i < 3;i++)??digitalWrite(Ring[4][i],LOW);??break;
  195. ? ?? ?default : break;
  196. ? ?? ?}
  197. ??}
  198. void Leaf_Run(byte n,boolean k)
  199. {
  200. ??if(k==true)
  201. ? ? switch(n){
  202. ? ?? ?case 0:
  203. ? ?? ???digitalWrite(Ring[1][0],HIGH);
  204. ? ?? ???digitalWrite(Ring[2][0],HIGH);
  205. ? ?? ???digitalWrite(Ring[2][1],HIGH);
  206. ? ?? ???digitalWrite(Ring[3][0],HIGH);
  207. ? ?? ???digitalWrite(Ring[4][0],HIGH);
  208. ? ?? ???break;
  209. ? ?? ?case 1:
  210. ? ?? ???digitalWrite(Ring[1][2],HIGH);
  211. ? ?? ???digitalWrite(Ring[2][5],HIGH);
  212. ? ?? ???digitalWrite(Ring[2][4],HIGH);
  213. ? ?? ???digitalWrite(Ring[3][2],HIGH);
  214. ? ?? ???digitalWrite(Ring[4][2],HIGH);
  215. ? ?? ???break;
  216. ? ?? ?case 2:
  217. ? ?? ???digitalWrite(Ring[1][1],HIGH);
  218. ? ?? ???digitalWrite(Ring[2][2],HIGH);
  219. ? ?? ???digitalWrite(Ring[2][3],HIGH);
  220. ? ?? ???digitalWrite(Ring[3][1],HIGH);
  221. ? ?? ???digitalWrite(Ring[4][1],HIGH);
  222. ? ?? ???break;
  223. ? ?? ?default: break;
  224. ? ?? ?}
  225. ? ? else switch(n){
  226. ? ?? ?case 0:
  227. ? ?? ???digitalWrite(Ring[1][0],LOW);
  228. ? ?? ???digitalWrite(Ring[2][0],LOW);
  229. ? ?? ???digitalWrite(Ring[2][1],LOW);
  230. ? ?? ???digitalWrite(Ring[3][0],LOW);
  231. ? ?? ???digitalWrite(Ring[4][0],LOW);
  232. ? ?? ???break;
  233. ? ?? ?case 1:
  234. ? ?? ???digitalWrite(Ring[1][2],LOW);
  235. ? ?? ???digitalWrite(Ring[2][5],LOW);
  236. ? ?? ???digitalWrite(Ring[2][4],LOW);
  237. ? ?? ???digitalWrite(Ring[3][2],LOW);
  238. ? ?? ???digitalWrite(Ring[4][2],LOW);
  239. ? ?? ???break;
  240. ? ?? ?case 2:
  241. ? ?? ???digitalWrite(Ring[1][1],LOW);
  242. ? ?? ???digitalWrite(Ring[2][2],LOW);
  243. ? ?? ???digitalWrite(Ring[2][3],LOW);
  244. ? ?? ???digitalWrite(Ring[3][1],LOW);
  245. ? ?? ???digitalWrite(Ring[4][1],LOW);
  246. ? ?? ???break;
  247. ? ?? ?default: break;
  248. ? ?? ?}
  249. ??}
复制代码



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

本版积分规则

QQ|Archiver|手机版|小黑屋|联系我们|YFRobot ( 苏ICP备13017135 )???

GMT+8, 2019-9-19 02:00 , Processed in 0.164436 second(s), 26 queries .

Powered by Discuz! X3.1

? 2001-2013 Comsenz Inc.

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