Advertisement
Guest User

M_STARKE

a guest
Mar 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.59 KB | None | 0 0
  1. #include "TimerOne.h"
  2. #include "SPI.h"
  3. #include "Adafruit_GFX.h"
  4. #include "Adafruit_ILI9340.h"
  5. #include "UTouch.h"
  6.  
  7. #if defined(__SAM3X8E__)
  8. #undef __FlashStringHelper::F(string_literal)
  9. #define F(string_literal) string_literal
  10. #endif
  11.  
  12. // LEDs //
  13.  
  14. #define led_wt_up_l_1 22
  15. #define led_wt_up_l_2 23
  16. #define led_wt_up_r_1 24
  17. #define led_wt_up_r_2 25
  18. #define led_wt_down_l_1 26
  19. #define led_wt_down_l_2 27
  20. #define led_wt_down_r_1 28
  21. #define led_wt_down_r_2 29
  22. #define led_ye_up_1 30
  23. #define led_ye_up_2 31
  24. #define led_ye_mid_1 32
  25. #define led_ye_mid_2 33
  26. #define led_ye_down_1 34
  27. #define led_ye_down_2 35
  28. #define led_gn_1 36
  29. #define led_gn_2 37
  30. #define led_rd_l 38
  31. #define led_rd_r 39
  32.  
  33. // Taster //
  34.  
  35. #define button_up 42
  36. #define button_down 44
  37. #define button_start 46
  38.  
  39. // Interruptpins //
  40.  
  41. #define startfoul_sensor_l 2
  42. #define startfoul_sensor_r 3
  43. #define speedsensor_in_l 18
  44. #define speedsensor_out_l 19
  45. #define speedsensor_in_r 20
  46. #define speedsensor_out_r 21
  47.  
  48. // Rundenzahllimit //
  49.  
  50. #define maxrunden 100
  51.  
  52.  
  53. /// DISPLAY ///
  54.  
  55. #define _sclk 52 //13 . lila
  56. #define _miso 50 //12 . schwarz
  57. #define _mosi 51 //11 . blau
  58. #define _cs 53 //10 . orange
  59. #define _dc 9 // . grün
  60. #define _rst 8 // . gelb
  61.  
  62.  
  63.  
  64. // Using software SPI is really not suggested, its incredibly slow
  65. //Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
  66. // Use hardware SPI
  67. Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
  68.  
  69.  
  70.  
  71.  
  72. // declare portstates for Lightsensors
  73.  
  74. int startfoul_sensor_l_status = 0;
  75. int startfoul_sensor_r_status = 0;
  76.  
  77. volatile bool fehlstart_l = false;
  78. volatile bool fehlstart_r = false;
  79.  
  80. volatile bool speed_in_l = false;
  81. volatile bool speed_out_l = false;
  82.  
  83. volatile bool speed_in_r = false;
  84. volatile bool speed_out_r = false;
  85.  
  86. bool rennenfertig_l = false;
  87. bool rennenfertig_r = false;
  88.  
  89. volatile byte state = LOW;
  90.  
  91. int sequenz = 1;
  92. int rundenzahl = 50;
  93.  
  94. int runde_l = 1;
  95. int runde_r = 1;
  96.  
  97. uint32_t zeit = 0;
  98. uint32_t startzeit = 0;
  99.  
  100. uint32_t rundenzeit_l;
  101. uint32_t rundenzeit_r;
  102.  
  103. uint32_t rennzeit_l[maxrunden];
  104. uint32_t rennzeit_r[maxrunden];
  105.  
  106. uint32_t speed1_l;
  107. uint32_t speed2_l;
  108.  
  109. uint32_t speed1_r;
  110. uint32_t speed2_r;
  111.  
  112. float speed_l[maxrunden];
  113. float speed_r[maxrunden];
  114.  
  115.  
  116.  
  117. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  118. // 0. Sequenz // INITIALISIERUNGS SEQUENZ
  119. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  120.  
  121. void setup() {
  122.  
  123.  
  124. int start = digitalRead(button_start);
  125. int up = digitalRead(button_up);
  126. int down = digitalRead(button_down);
  127.  
  128. Serial.begin(9600);
  129. tft.begin();
  130.  
  131. pinMode(startfoul_sensor_l, INPUT_PULLUP); // Der Sensor liefert immer eine Spannung (5V oder 0V) deshalb keinen pullup verwenden
  132. pinMode(startfoul_sensor_r, INPUT_PULLUP); // Der Sensor liefert immer eine Spannung (5V oder 0V) deshalb keinen pullup verwenden
  133. pinMode(speedsensor_in_l, INPUT_PULLUP);
  134. pinMode(speedsensor_out_l, INPUT_PULLUP);
  135. pinMode(speedsensor_in_r, INPUT_PULLUP);
  136. pinMode(speedsensor_out_l, INPUT_PULLUP);
  137.  
  138. pinMode(button_up, INPUT);
  139. pinMode(button_down, INPUT);
  140. pinMode(button_start, INPUT);
  141.  
  142. pinMode(led_wt_up_l_1, OUTPUT);
  143. pinMode(led_wt_up_l_2, OUTPUT);
  144. pinMode(led_wt_up_r_1, OUTPUT);
  145. pinMode(led_wt_up_r_2, OUTPUT);
  146. pinMode(led_wt_down_l_1, OUTPUT);
  147. pinMode(led_wt_down_l_2, OUTPUT);
  148. pinMode(led_wt_down_r_1, OUTPUT);
  149. pinMode(led_wt_down_r_2, OUTPUT);
  150. pinMode(led_ye_up_1, OUTPUT);
  151. pinMode(led_ye_up_2, OUTPUT);
  152. pinMode(led_ye_mid_1, OUTPUT);
  153. pinMode(led_ye_mid_2, OUTPUT);
  154. pinMode(led_ye_down_1, OUTPUT);
  155. pinMode(led_ye_down_2, OUTPUT);
  156. pinMode(led_gn_1, OUTPUT);
  157. pinMode(led_gn_2, OUTPUT);
  158. pinMode(led_rd_l, OUTPUT);
  159. pinMode(led_rd_r, OUTPUT);
  160.  
  161.  
  162.  
  163.  
  164.  
  165. tft.setRotation(3);
  166. tft.fillScreen(ILI9340_BLACK);
  167. tft.setCursor(10, 50);
  168. tft.setTextColor(ILI9340_WHITE);
  169. tft.setTextSize(2);
  170. tft.print("Projektarbeit 2017/ 2018");
  171. tft.setCursor(10, 120);
  172. tft.setTextColor(ILI9340_BLUE);
  173. tft.setTextSize(2);
  174. tft.print("Technikerschule Augsburg");
  175. tft.setCursor(10, 190);
  176. tft.setTextColor(ILI9340_RED);
  177. tft.setTextSize(3);
  178. tft.print(" Markus Starke");
  179. delay(10000);
  180. tft.fillScreen(ILI9340_BLACK);
  181.  
  182.  
  183. ///////////////////////// Interruptroutinen ////////////////////////////////////////
  184. ////////////////////////////////////////////////////////////////////////////////////
  185. ///////////////////////// Zeit- & Rundensensoren ///////////////////////////////////
  186. attachInterrupt(digitalPinToInterrupt(startfoul_sensor_l), startfoul_l, RISING);
  187. attachInterrupt(digitalPinToInterrupt(startfoul_sensor_r), startfoul_r, RISING);
  188.  
  189. ///////////////////////// GeschwindigkeitsSensoren /////////////////////////////////
  190. attachInterrupt(digitalPinToInterrupt(speedsensor_in_l), f_speed_in_l, FALLING);
  191. attachInterrupt(digitalPinToInterrupt(speedsensor_out_l), f_speed_out_l, FALLING);
  192.  
  193. attachInterrupt(digitalPinToInterrupt(speedsensor_in_r), f_speed_in_r, FALLING);
  194. attachInterrupt(digitalPinToInterrupt(speedsensor_out_r), f_speed_out_r, FALLING);
  195.  
  196. }
  197.  
  198.  
  199. void loop()
  200. {
  201.  
  202. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  203. // 1. Sequenz // MENÜ SEQUENZ ///////////////////////
  204. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  205. if(sequenz == 1)
  206. {
  207.  
  208. menu();
  209. sequenz = 1;
  210. }
  211. while (sequenz == 1) // Sequenzabfrage
  212. {
  213.  
  214.  
  215. if(digitalRead(button_start))
  216. {
  217. tft.fillScreen(ILI9340_BLACK);
  218. tft.setCursor(120,150);
  219. tft.setTextColor(ILI9340_RED);
  220. tft.setTextSize(3);
  221. tft.print("Ampelsignal...");
  222. sequenz = 2;
  223. }
  224.  
  225. if(digitalRead(button_up))
  226. {
  227. rundenzahl++;
  228. tft.fillRect(160,75, 60, 40, ILI9340_BLACK);
  229. tft.setCursor(165, 80);
  230. tft.setTextColor(ILI9340_WHITE);
  231. tft.setTextSize(3);
  232. tft.print(rundenzahl);
  233.  
  234. delay(250);
  235. }
  236.  
  237. if(digitalRead(button_down))
  238. {
  239. rundenzahl--;
  240.  
  241. tft.fillRect(160,75, 60, 40, ILI9340_BLACK);
  242. tft.setCursor(165, 80);
  243. tft.setTextColor(ILI9340_WHITE);
  244. tft.setTextSize(3);
  245. tft.print(rundenzahl);
  246.  
  247. delay(250);
  248. }
  249.  
  250. }
  251. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  252. // 2. Sequenz // RENN SEQUENZ //////////////////////////////////////////////
  253. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  254.  
  255. if(sequenz==2)
  256. {
  257. startzeit = millis(); //startzeit ampel
  258. }
  259.  
  260.  
  261. while (sequenz == 2)
  262. {
  263. startsequenz();
  264.  
  265.  
  266. if(fehlstart_l)
  267. {
  268.  
  269. tft.setRotation(3);
  270. tft.fillScreen(ILI9340_BLACK);
  271.  
  272. tft.setCursor(10, 80);
  273. tft.setTextColor(ILI9340_RED);
  274. tft.setTextSize(2);
  275. tft.print(" FEHLSTART !!!");
  276. tft.setCursor(850, 120);
  277. tft.setTextColor(ILI9340_WHITE);
  278. tft.setTextSize(2);
  279. tft.print(" - linke Fahrbahn -");
  280.  
  281. digitalWrite(led_rd_l, HIGH);
  282.  
  283. digitalWrite(led_wt_up_l_1, LOW);
  284. digitalWrite(led_wt_up_l_2, LOW);
  285. digitalWrite(led_wt_up_r_1, LOW);
  286. digitalWrite(led_wt_up_r_2, LOW);
  287. digitalWrite(led_wt_down_l_1, LOW);
  288. digitalWrite(led_wt_down_l_2, LOW);
  289. digitalWrite(led_wt_down_r_1, LOW);
  290. digitalWrite(led_wt_down_r_2, LOW);
  291. digitalWrite(led_ye_up_1, LOW);
  292. digitalWrite(led_ye_up_2, LOW);
  293. digitalWrite(led_ye_mid_1,LOW);
  294. digitalWrite(led_ye_mid_2,LOW);
  295. digitalWrite(led_ye_down_1,LOW);
  296. digitalWrite(led_ye_down_2, LOW);
  297. digitalWrite(led_gn_1, LOW);
  298. digitalWrite(led_gn_2,LOW);
  299. digitalWrite(led_rd_r, LOW);
  300. delay(10000);
  301.  
  302. digitalWrite(led_rd_l, LOW);
  303.  
  304. fehlstart_l = false;
  305.  
  306. menu();
  307.  
  308. sequenz = 1;
  309. }
  310.  
  311.  
  312. if(fehlstart_r)
  313. {
  314.  
  315. tft.setRotation(3);
  316. tft.fillScreen(ILI9340_BLACK);
  317. tft.setCursor(10, 80);
  318. tft.setTextColor(ILI9340_RED);
  319. tft.setTextSize(2);
  320. tft.print(" FEHLSTART !!!");
  321. tft.setCursor(10, 120);
  322. tft.setTextColor(ILI9340_WHITE);
  323. tft.setTextSize(2);
  324. tft.print(" - rechte Fahrbahn -");
  325. tft.setCursor(10, 160);
  326. tft.setTextColor(ILI9340_WHITE);
  327.  
  328. digitalWrite(led_rd_r, HIGH);
  329.  
  330. digitalWrite(led_wt_up_l_1, LOW);
  331. digitalWrite(led_wt_up_l_2, LOW);
  332. digitalWrite(led_wt_up_r_1, LOW);
  333. digitalWrite(led_wt_up_r_2, LOW);
  334. digitalWrite(led_wt_down_l_1, LOW);
  335. digitalWrite(led_wt_down_l_2, LOW);
  336. digitalWrite(led_wt_down_r_1, LOW);
  337. digitalWrite(led_wt_down_r_2, LOW);
  338. digitalWrite(led_ye_up_1, LOW);
  339. digitalWrite(led_ye_up_2, LOW);
  340. digitalWrite(led_ye_mid_1,LOW);
  341. digitalWrite(led_ye_mid_2,LOW);
  342. digitalWrite(led_ye_down_1,LOW);
  343. digitalWrite(led_ye_down_2, LOW);
  344. digitalWrite(led_gn_1, LOW);
  345. digitalWrite(led_gn_2,LOW);
  346. digitalWrite(led_rd_l, LOW);
  347. delay(10000);
  348.  
  349. digitalWrite(led_rd_r, LOW);
  350.  
  351. fehlstart_r = false;
  352.  
  353. menu();
  354.  
  355. sequenz = 1;
  356. }
  357.  
  358. }
  359.  
  360. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  361. // 3. Sequenz // AUSWERT SEQUENZ ////////////////////////////////////////////////////////
  362. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  363. if(sequenz==3)
  364. {
  365.  
  366. //alle zeiten zurücksetzen
  367.  
  368. rennzeit_l[runde_l-1] = millis();
  369. rennzeit_r[runde_r-1] = millis();
  370.  
  371. ////////////////////////////////////////////////////////////////////////////////
  372. ////////////////////////////// GRUNDSTRUKTUR RENNANZEIGE ZEIT ZAHL (SPEED) /////
  373. ////////////////////////////////////////////////////////////////////////////////
  374.  
  375. tft.fillScreen(ILI9340_BLACK);
  376. tft.setRotation(3);
  377.  
  378. tft.setCursor(20, 5);
  379. tft.setTextColor(ILI9340_CYAN);
  380. tft.setTextSize(2);
  381. tft.print("Rennen");
  382.  
  383. tft.drawLine(0, 30, 320, 30, ILI9340_WHITE);
  384. //tft.drawLine(0, 70, 320, 70, ILI9340_WHITE);
  385. tft.drawLine(160, 30, 160, 60, ILI9340_WHITE);
  386.  
  387. tft.setCursor(55, 45);
  388. tft.setTextColor(ILI9340_RED);
  389. tft.setTextSize(3);
  390. tft.print("1");
  391.  
  392. tft.setCursor(245, 45);
  393. tft.setTextColor(ILI9340_RED);
  394. tft.setTextSize(3);
  395. tft.print("2");
  396.  
  397. tft.setCursor(132, 65);
  398. tft.setTextColor(ILI9340_WHITE);
  399. tft.setTextSize(2);
  400. tft.print("RUNDE");
  401. tft.drawRect(120, 60, 80, 25, ILI9340_WHITE);
  402. tft.drawLine(160, 85, 160, 120, ILI9340_WHITE);
  403.  
  404. tft.setCursor(30, 95);
  405. tft.setTextColor(ILI9340_WHITE);
  406. tft.setTextSize(2);
  407. tft.print("0"); tft.print(" / "); tft.print(rundenzahl);
  408.  
  409. tft.setCursor(220, 95);
  410. tft.setTextColor(ILI9340_WHITE);
  411. tft.setTextSize(2);
  412. tft.print("0"); tft.print(" / "); tft.print(rundenzahl);
  413.  
  414. tft.setCursor(103, 125);
  415. tft.setTextColor(ILI9340_WHITE);
  416. tft.setTextSize(2);
  417. tft.print("RUNDENZEIT");
  418. tft.drawRect(90, 120, 140, 25, ILI9340_WHITE);
  419. tft.drawLine(160, 145, 160, 180, ILI9340_WHITE);
  420.  
  421. tft.setCursor(30, 155);
  422. tft.setTextColor(ILI9340_WHITE);
  423. tft.setTextSize(2);
  424. tft.print(" "); tft.print(" s");
  425.  
  426. tft.setCursor(220, 155);
  427. tft.setTextColor(ILI9340_WHITE);
  428. tft.setTextSize(2);
  429. tft.print(" "); tft.print(" s");
  430.  
  431. tft.setCursor(130, 185);
  432. tft.setTextColor(ILI9340_WHITE);
  433. tft.setTextSize(2);
  434. tft.print("SPEED");
  435. tft.drawRect(120, 180, 80, 25, ILI9340_WHITE);
  436. tft.drawLine(160, 205, 160, 320, ILI9340_WHITE);
  437.  
  438.  
  439. tft.setCursor(20, 215);
  440. tft.setTextColor(ILI9340_WHITE);
  441. tft.setTextSize(2);
  442. tft.print(" "); tft.print(" m/s");
  443.  
  444. tft.setCursor(180, 215);
  445. tft.setTextColor(ILI9340_WHITE);
  446. tft.setTextSize(2);
  447. tft.print(" "); tft.print(" m/s");
  448.  
  449. }
  450.  
  451.  
  452. while ((sequenz == 3) && !(rennenfertig_l) && !(rennenfertig_r))
  453. {
  454.  
  455.  
  456. if(speed_in_l)
  457. {
  458. speed1_l = millis();
  459. speed_in_l = false;
  460. }
  461.  
  462.  
  463. if(speed_out_l)
  464. {
  465. speed2_l = millis();
  466. float speedfloat_l = (float) (speed2_l - speed1_l) ;
  467. speed_l[runde_l] = ( (0,15) / (speedfloat_l) * 10 ); // v = s / t
  468.  
  469. tft.fillRect(10,210, 140, 25, ILI9340_BLACK);
  470. tft.setCursor(20, 215); ///////// Ausgabe, Geschwindigkeit
  471. tft.setTextColor(ILI9340_WHITE);
  472. tft.setTextSize(2);
  473. tft.print(speed_l[runde_l]); tft.print(" m/s");
  474. speed_out_l = false;
  475.  
  476. }
  477.  
  478.  
  479. if(speed_in_r)
  480. {
  481. speed1_r = millis();
  482. speed_in_r = false;
  483. }
  484.  
  485.  
  486. if(speed_out_r)
  487. {
  488. speed2_r = millis();
  489. float speedfloat_r = (float) (speed2_r - speed1_r);
  490.  
  491. speed_r[runde_r] = ( (0,15) / (speedfloat_r) * 10) ; // v = s / t
  492.  
  493. tft.fillRect(180,210, 140, 25, ILI9340_BLACK);
  494. tft.setCursor(180, 215); ////////// Ausgabe, Geschwindigkeit
  495. tft.setTextColor(ILI9340_WHITE);
  496. tft.setTextSize(2);
  497. tft.print(speed_r[runde_r]); tft.print(" m/s");
  498.  
  499. speed_out_r = false;
  500.  
  501. }
  502.  
  503.  
  504. if(fehlstart_l) //SENSOR fahrbahn links
  505. {
  506. digitalWrite(led_gn_1, LOW);
  507. digitalWrite(led_gn_2, LOW);
  508. rennzeit_l[runde_l] = millis();
  509.  
  510. rundenzeit_l = rennzeit_l[runde_l] - rennzeit_l[runde_l-1]; //// rundenzeit = Zeit auf Display schreiben
  511. runde_l++;
  512.  
  513. float float_rundenzeit_l = ((float)rundenzeit_l)/1000;
  514.  
  515. // Rundenweise Ausgabe von RundenZeit und RundenZahl
  516.  
  517. tft.fillRect(30, 150, 100, 25, ILI9340_BLACK);
  518. tft.setCursor(30, 155);
  519. tft.setTextColor(ILI9340_WHITE);
  520. tft.setTextSize(2);
  521. tft.print(float_rundenzeit_l); tft.print(" s");
  522.  
  523. tft.fillRect(30, 90, 80, 25, ILI9340_BLACK);
  524. tft.setCursor(30, 95);
  525. tft.setTextColor(ILI9340_WHITE);
  526. tft.setTextSize(2);
  527. tft.print(runde_l); tft.print(" / "); tft.print(rundenzahl);
  528.  
  529. delay(50);
  530. fehlstart_l = false;
  531.  
  532.  
  533.  
  534. }
  535.  
  536.  
  537. if(fehlstart_r) //SENSOR fahrbahn rechts
  538. {
  539. digitalWrite(led_gn_1, LOW);
  540. digitalWrite(led_gn_2, LOW);
  541. rennzeit_r[runde_r] = millis();
  542.  
  543. rundenzeit_r = rennzeit_r[runde_r] - rennzeit_r[runde_r-1]; //rundenzeit = Zeit auf Display schreiben
  544. runde_r++;
  545.  
  546. float float_rundenzeit_r = ((float)rundenzeit_r)/1000;
  547.  
  548. /////////////////////////////////////////////////////////////
  549. ///// Rundenweise Ausgabe von RundenZeit und RundenZahl /////
  550.  
  551. tft.fillRect(220, 150, 100, 25, ILI9340_BLACK);
  552. tft.setCursor(220, 155);
  553. tft.setTextColor(ILI9340_WHITE);
  554. tft.setTextSize(2);
  555. tft.print(float_rundenzeit_r); tft.print(" s");
  556.  
  557. tft.fillRect(220, 90, 80, 25, ILI9340_BLACK);
  558. tft.setCursor(220, 95);
  559. tft.setTextColor(ILI9340_WHITE);
  560. tft.setTextSize(2);
  561. tft.print(runde_r); tft.print(" / "); tft.print(rundenzahl);
  562.  
  563. /////////////////////////////////////////////////////////////
  564. delay(50);
  565. fehlstart_r = false;
  566.  
  567. }
  568.  
  569.  
  570.  
  571. if(rundenzahl + 1 == runde_l)
  572. {
  573. rennenfertig_l = true;
  574. sequenz = 4;
  575. }
  576.  
  577. if(rundenzahl + 1 == runde_r)
  578. {
  579. rennenfertig_r = true;
  580. sequenz = 4;
  581. }
  582. }
  583.  
  584.  
  585. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  586. // 4. Sequenz ////////////////////////////////////////////////////////////////////////////////////////////
  587. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  588. if(sequenz==4)
  589. {
  590.  
  591. }
  592.  
  593. while(sequenz == 4)
  594. {
  595.  
  596.  
  597. if(rennenfertig_l)
  598. {
  599. //////// Ausgabe Display ////////
  600. tft.setRotation(3);
  601. tft.fillScreen(ILI9340_BLACK);
  602. tft.setCursor(10, 60);
  603. tft.setTextColor(ILI9340_BLUE);
  604. tft.setTextSize(3);
  605. tft.print(":: GEWINNER ::");
  606.  
  607. tft.setCursor(40, 160);
  608. tft.setTextColor(ILI9340_RED);
  609. tft.setTextSize(3);
  610. tft.print("linkes Auto");
  611. delay(10000);
  612.  
  613. rundenzeit_l = 0;
  614. rundenzeit_r = 0;
  615. runde_l = 1;
  616. runde_r = 1;
  617. rennenfertig_l = false;
  618. rennenfertig_r = false;
  619.  
  620. fehlstart_l = false; //////
  621. fehlstart_r = false; //////
  622.  
  623. tft.fillScreen(ILI9340_BLACK);
  624. tft.setCursor(40, 100);
  625. tft.setTextColor(ILI9340_WHITE);
  626. tft.setTextSize(2);
  627. tft.print("Bitte START tippen");
  628. }
  629.  
  630. if(rennenfertig_r)
  631. {
  632. //////// Ausgabe Display ////////
  633.  
  634. tft.setRotation(3);
  635. tft.fillScreen(ILI9340_BLACK);
  636. tft.setCursor(10, 60);
  637. tft.setTextColor(ILI9340_BLUE);
  638. tft.setTextSize(3);
  639. tft.print(":: GEWINNER ::");
  640.  
  641. tft.setCursor(40, 160);
  642. tft.setTextColor(ILI9340_RED);
  643. tft.setTextSize(3);
  644. tft.print("rechtes Auto");
  645. delay(10000);
  646.  
  647. rundenzeit_l= 0;
  648. rundenzeit_r= 0;
  649. runde_l = 1;
  650. runde_r = 1;
  651. rennenfertig_r = false;
  652. rennenfertig_r = false;
  653. fehlstart_l = false; //////
  654. fehlstart_r = false; //////
  655.  
  656. tft.fillScreen(ILI9340_BLACK);
  657.  
  658. tft.setCursor(40, 100);
  659. tft.setTextColor(ILI9340_WHITE);
  660. tft.setTextSize(2);
  661. tft.print("Bitte START tippen");
  662. }
  663.  
  664.  
  665. if(digitalRead(button_start))
  666. {
  667. sequenz = 1;
  668. }
  669.  
  670. }
  671.  
  672.  
  673. }
  674.  
  675.  
  676. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  677. // Funktionen (nicht mehr in der Loop)
  678. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  679.  
  680.  
  681. void startup() {
  682.  
  683. tft.setRotation(3);
  684. tft.fillScreen(ILI9340_BLACK);
  685. tft.setCursor(10, 80);
  686. tft.setTextColor(ILI9340_WHITE);
  687. tft.setTextSize(2);
  688. tft.print("Projektarbeit 2017/ 2018");
  689. tft.setCursor(10, 120);
  690. tft.setTextColor(ILI9340_WHITE);
  691. tft.setTextSize(2);
  692. tft.print("Technikerschule Augsburg");
  693. tft.setCursor(10, 160);
  694. tft.setTextColor(ILI9340_WHITE);
  695. tft.setTextSize(2);
  696. tft.print("K16, Markus Starke");
  697. delay(5000);
  698.  
  699. }
  700.  
  701. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  702.  
  703. void menu()
  704. {
  705.  
  706.  
  707.  
  708. tft.fillScreen(ILI9340_BLACK);
  709. tft.setRotation(3);
  710.  
  711. tft.setCursor(20, 5);
  712. tft.setTextColor(ILI9340_CYAN);
  713. tft.setTextSize(3);
  714. tft.print("Men"); tft.print((char)129);
  715.  
  716.  
  717. tft.setCursor(20, 80);
  718. tft.setTextColor(ILI9340_WHITE);
  719. tft.setTextSize(3);
  720. tft.print("Runden:");
  721.  
  722. tft.setCursor(40, 140);
  723. tft.setTextColor(ILI9340_WHITE);
  724. tft.setTextSize(2);
  725. tft.print("m/s");
  726.  
  727. tft.setCursor(40, 205);
  728. tft.setTextColor(ILI9340_WHITE);
  729. tft.setTextSize(2);
  730. tft.print("km/h");
  731.  
  732. tft.setCursor(165, 80);
  733. tft.setTextColor(ILI9340_WHITE);
  734. tft.setTextSize(3);
  735. tft.print(rundenzahl);
  736.  
  737. tft.setCursor(252, 50);
  738. tft.setTextColor(ILI9340_WHITE);
  739. tft.setTextSize(3);
  740. tft.print("+");
  741.  
  742. tft.setCursor(252, 110);
  743. tft.setTextColor(ILI9340_WHITE);
  744. tft.setTextSize(3);
  745. tft.print("-");
  746.  
  747. tft.setCursor(200, 198);
  748. tft.setTextColor(ILI9340_WHITE);
  749. tft.setTextSize(2);
  750. tft.print("START");
  751.  
  752. tft.drawRect(20,130,80,40, ILI9340_RED);
  753.  
  754. tft.drawRect(20,190,80,40, ILI9340_RED);
  755. tft.drawRect(220,40,80,40, ILI9340_RED);
  756. tft.drawTriangle(220,40,260,20,300,40, ILI9340_RED);
  757. tft.drawRect(220,100,80,40, ILI9340_RED);
  758. tft.drawTriangle(220,140, 260,160, 300,140, ILI9340_RED);
  759. tft.drawRect(160,180,140,50, ILI9340_RED);
  760.  
  761.  
  762.  
  763. }
  764.  
  765. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  766.  
  767. void startsequenz()
  768. {
  769.  
  770. if(millis() >= startzeit + 6000)
  771. {
  772. digitalWrite(led_ye_down_1, LOW);
  773. digitalWrite(led_ye_down_2, LOW);
  774. digitalWrite(led_gn_1, HIGH);
  775. digitalWrite(led_gn_2, HIGH);
  776. sequenz=3;
  777.  
  778. uint32_t rennzeit_start_l = millis();
  779. uint32_t rennzeit_start_r = millis();
  780. }
  781.  
  782. else if(millis() >= startzeit + 5500)
  783. {
  784. digitalWrite(led_ye_mid_1, LOW);
  785. digitalWrite(led_ye_mid_2, LOW);
  786. digitalWrite(led_ye_down_1, HIGH);
  787. digitalWrite(led_ye_down_2, HIGH);
  788. }
  789.  
  790. else if(millis() >= startzeit + 5000)
  791. {
  792. digitalWrite(led_ye_up_1, LOW);
  793. digitalWrite(led_ye_up_2, LOW);
  794. digitalWrite(led_ye_mid_1, HIGH);
  795. digitalWrite(led_ye_mid_2, HIGH);
  796. }
  797.  
  798. else if(millis() >= startzeit + 4500)
  799. {
  800. digitalWrite(led_wt_down_r_1, LOW);
  801. digitalWrite(led_wt_down_r_2, LOW);
  802. digitalWrite(led_ye_up_1, HIGH);
  803. digitalWrite(led_ye_up_2, HIGH);
  804. }
  805.  
  806. else if(millis() >= startzeit + 3000)
  807. {
  808. digitalWrite(led_wt_down_l_1, LOW);
  809. digitalWrite(led_wt_down_l_2, LOW);
  810. digitalWrite(led_wt_down_r_1, HIGH);
  811. digitalWrite(led_wt_down_r_2, HIGH);
  812. }
  813.  
  814. else if(millis() >= startzeit + 2000)
  815. {
  816. digitalWrite(led_wt_up_r_1, LOW);
  817. digitalWrite(led_wt_up_r_2, LOW);
  818. digitalWrite(led_wt_down_l_1, HIGH);
  819. digitalWrite(led_wt_down_l_2, HIGH);
  820. }
  821.  
  822. else if(millis() >= startzeit + 1000)
  823. {
  824. digitalWrite(led_wt_up_l_1, LOW);
  825. digitalWrite(led_wt_up_l_2, LOW);
  826. digitalWrite(led_wt_up_r_1, HIGH);
  827. digitalWrite(led_wt_up_r_2, HIGH);
  828. }
  829.  
  830. else if(millis() >= startzeit)
  831. {
  832. digitalWrite(led_wt_up_l_1, HIGH);
  833. digitalWrite(led_wt_up_l_2, HIGH);
  834. }
  835. }
  836.  
  837. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  838.  
  839. void startfoul_l()
  840. {
  841. fehlstart_l = true;
  842. }
  843.  
  844. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  845.  
  846. void startfoul_r()
  847. {
  848. fehlstart_r = true;
  849. }
  850.  
  851. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  852.  
  853. void f_speed_in_l()
  854. {
  855. speed_in_l = true;
  856. }
  857.  
  858. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  859.  
  860. void f_speed_out_l()
  861. {
  862. speed_out_l = true;
  863. }
  864.  
  865. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  866.  
  867. void f_speed_in_r()
  868. {
  869. speed_in_r = true;
  870. }
  871.  
  872. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  873.  
  874. void f_speed_out_r()
  875. {
  876. speed_out_r = true;
  877. }
  878.  
  879. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement