You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

______(2).ino 5.8 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #include <Arduino.h>
  2. #include <Wire.h>
  3. #include <Servo.h>
  4. double _ABVAR_1_i = 0.0 ;
  5. int a = 0;
  6. int b = 0;
  7. Servo servo_pin_4;
  8. //TCS230连接设置
  9. const int s0 = A0;
  10. const int s1 = A1;
  11. const int s2 = A4;
  12. const int s3 = A5;
  13. const int out = 8; //10
  14. const int led = 7;
  15. // Variables
  16. int red = 0;
  17. int green = 0;
  18. int blue = 0;
  19. void trunleft();
  20. void trunright();
  21. void forward();
  22. void forward1();
  23. void forward2();//20
  24. void stop1();
  25. void color() ;
  26. int color_see();
  27. void zha_qi_qiu();
  28. const int zuo=3;
  29. const int you=17;
  30. int c=0;
  31. int _ABVAR_2_a = 0;
  32. int _ABVAR_3_b = 0;
  33. void setup()
  34. {
  35. pinMode( zuo, INPUT);
  36. pinMode( you, INPUT);
  37. pinMode( 16, INPUT);
  38. pinMode( 14, INPUT);
  39. pinMode( 10, OUTPUT);
  40. pinMode( 6, OUTPUT);
  41. pinMode( 5, OUTPUT);
  42. pinMode( 9, OUTPUT);
  43. _ABVAR_1_i = 0.0 ;
  44. servo_pin_4.attach(4);
  45. pinMode(s0, OUTPUT);
  46. pinMode(s1, OUTPUT);
  47. pinMode(s2, OUTPUT);
  48. pinMode(s3, OUTPUT);
  49. pinMode(out, INPUT);
  50. pinMode(led, OUTPUT);
  51. digitalWrite(s0, HIGH);
  52. digitalWrite(s1, HIGH);
  53. }
  54. void loop()
  55. {
  56. /* if(!(digitalRead(16)))
  57. {
  58. forward();
  59. }
  60. else*/
  61. {if (( digitalRead(you) && digitalRead(zuo) ))
  62. {
  63. forward();
  64. }
  65. else
  66. {
  67. if (( !( digitalRead(you) ) && digitalRead(zuo) ))
  68. {
  69. trunright();
  70. }
  71. else
  72. {
  73. if (( digitalRead(you) && !( digitalRead(zuo) ) ))
  74. {
  75. trunleft();
  76. }
  77. else
  78. {
  79. if (( !( digitalRead(you) ) && !( digitalRead(zuo) ) ))
  80. {
  81. _ABVAR_1_i = ( _ABVAR_1_i + 1 ) ;
  82. if (( ( _ABVAR_1_i ) == ( 1 ) ))
  83. {
  84. forward1();
  85. delay( 3500 );
  86. }
  87. else
  88. {
  89. if (( ( _ABVAR_1_i ) == ( 2 ) ))
  90. {
  91. forward1_1();
  92. delay( 3700 );
  93. }
  94. else
  95. {
  96. if (( ( _ABVAR_1_i ) == ( 3 ) ))
  97. {
  98. stop1();
  99. digitalWrite(led, HIGH);
  100. delay(500);
  101. color();
  102. digitalWrite(led, LOW);
  103. if (red < blue && red < green)
  104. {
  105. _ABVAR_2_a = 1;
  106. //LcdDisplay(" - (Red Color)");
  107. }
  108. else if (blue < red && blue < green)
  109. {
  110. _ABVAR_2_a = 2;
  111. // LcdDisplay(" - (Blue Color)");
  112. }
  113. else if (green < red && green < blue)
  114. {
  115. _ABVAR_2_a = 3;
  116. // LcdDisplay(" - (Green Color)");
  117. }
  118. while(((_ABVAR_2_a)!= (_ABVAR_3_b)))
  119. {
  120. pan_duan_yan_se();
  121. }
  122. duo_ji();
  123. /*int j;
  124. stop1();
  125. a =( color_see());
  126. for( j=1;j<=3;j++)
  127. {
  128. forward2();
  129. delay( 1000 );
  130. stop1();
  131. b = color_see();
  132. if(a==b)
  133. { zha_qi_qiu() ;
  134. forward();
  135. delay(4000);
  136. stop1();
  137. delay(4000);}
  138. }
  139. //zha wan qi qiu */
  140. }
  141. }//three time
  142. }//two time
  143. }// one time
  144. }
  145. }
  146. }
  147. }
  148. }
  149. void forward()
  150. {
  151. analogWrite(9 , 180);
  152. analogWrite(10 , 0);
  153. analogWrite(5 , 193);
  154. analogWrite(6 , 0);
  155. }
  156. void trunleft()
  157. {
  158. analogWrite(9 , 0);
  159. analogWrite(10 , 120);
  160. analogWrite(5 , 120);
  161. analogWrite(6 , 0);
  162. }
  163. void forward2()
  164. {
  165. analogWrite(9 , 100);
  166. analogWrite(10 , 0);
  167. analogWrite(5 , 110);
  168. analogWrite(6 , 0);
  169. }
  170. void stop1()
  171. {
  172. analogWrite(9 , 0);
  173. analogWrite(10 , 0);
  174. analogWrite(5 , 0);
  175. analogWrite(6 , 0);
  176. }
  177. void forward1()
  178. {
  179. analogWrite(9 , 200);
  180. analogWrite(10 , 0);
  181. analogWrite(5 , 200);
  182. analogWrite(6 , 0);
  183. }
  184. void forward1_1()
  185. {
  186. analogWrite(9 , 250);
  187. analogWrite(10 , 0);
  188. analogWrite(5 , 250);
  189. analogWrite(6 , 0);
  190. }
  191. void trunright()
  192. {
  193. analogWrite(9 , 120);
  194. analogWrite(10 , 0);
  195. analogWrite(5 , 0);
  196. analogWrite(6 , 120);
  197. }
  198. /*int color_see()
  199. {
  200. delay(150);
  201. digitalWrite(led, HIGH);
  202. delay(150);
  203. color();
  204. if (red < blue && red < green)
  205. {
  206. return 1;
  207. }
  208. else if (blue < red && blue < green)
  209. {
  210. return 2;
  211. }
  212. else if (green < red && green < blue)
  213. {
  214. return 3;
  215. }
  216. }
  217. */
  218. void color()
  219. {
  220. digitalWrite(s2, LOW);
  221. digitalWrite(s3, LOW);
  222. red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
  223. digitalWrite(s3, HIGH);
  224. blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
  225. digitalWrite(s2, HIGH);
  226. green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
  227. }
  228. void duo_ji()
  229. {
  230. for(int i=0;i<3;i++)
  231. {
  232. servo_pin_4.write( 90 );
  233. delay( 300 );
  234. servo_pin_4.write( 180 );
  235. delay( 600 );
  236. servo_pin_4.write( 90 );
  237. delay( 300 );
  238. }
  239. }
  240. void pan_duan_yan_se()
  241. {
  242. forward();
  243. delay(600);
  244. stop1();
  245. digitalWrite(led, HIGH);
  246. delay(500);
  247. color();
  248. digitalWrite(led, LOW);
  249. if (red < blue && red < green)
  250. {
  251. _ABVAR_3_b = 1;
  252. // LcdDisplay(" - (Red Color)");
  253. }
  254. else if (blue < red && blue < green)
  255. {
  256. _ABVAR_3_b = 2;
  257. // LcdDisplay(" - (Blue Color)");
  258. }
  259. else if (green < red && green < blue)
  260. {
  261. _ABVAR_3_b = 3;
  262. // LcdDisplay(" - (Green Color)");
  263. }
  264. }
  265. /*void zha_qi_qiu()
  266. {
  267. for(int i=0;i<3;i++)
  268. {
  269. servo_pin_4.write(90);
  270. delay(1000);
  271. servo_pin_4.write(150);
  272. delay(1000);
  273. servo_pin_4.write(90);
  274. delay(1000);
  275. }
  276. }*/

TensorLayer3.0 是一款兼容多种深度学习框架为计算后端的深度学习库。计划兼容TensorFlow, Pytorch, MindSpore, Paddle.