Guest User

qwerty2350

a guest
Jan 4th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.63 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. #define led_wt_up_l_1     24
  13. #define led_wt_up_l_2     25
  14. #define led_wt_up_r_1     26
  15. #define led_wt_up_r_2     27
  16. #define led_wt_down_l_1   28
  17. #define led_wt_down_l_2   29
  18. #define led_wt_down_r_1   30
  19. #define led_wt_down_r_2   31
  20. #define led_ye_up         32
  21. #define led_ye_mid        33  
  22. #define led_ye_down       34
  23. #define led_gn            35
  24. #define led_rd_l          36  
  25. #define led_rd_r          37
  26. #define button_up              42
  27. #define button_down            43  
  28. #define button_start           44
  29.  
  30. // These are the pins used for the UNO
  31. // for Due/Mega/Leonardo use the hardware SPI pins (which are different)
  32. #define _sclk 52    //13
  33. #define _miso 50    //12    //für SW SPI, jedoch langsamer!
  34. #define _mosi 51    //11
  35. #define _cs 53      //10
  36. #define _dc 9      
  37. #define _rst 8      
  38.  
  39.  
  40.  
  41. // Using software SPI is really not suggested, its incredibly slow
  42. //Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);
  43. // Use hardware SPI
  44. Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
  45.  
  46. const byte startfoul_sensor_l = 2;
  47. const byte startfoul_sensor_r = 3;
  48.  
  49. // declare portstates for Lightsensors
  50.  
  51. int startfoul_sensor_l_status = 0;
  52. int startfoul_sensor_r_status = 0;
  53.  
  54.  
  55. volatile byte state = LOW;
  56.  
  57. unsigned long x = 0;
  58. unsigned long y = 0;
  59. unsigned long z = 0;
  60.  
  61. int programmabschnitt = 2;
  62. int rundenzahl = 3;
  63. int sequenzende = 0;
  64. int runde_l = 0;
  65. int runde_r = 0;
  66.  
  67. uint8_t zeit = 0;
  68. uint8_t startzeit = 0;
  69. uint8_t rennzeit_start_l = 0;
  70. uint8_t rennzeit_start_r = 0;
  71.  
  72.  
  73. void startfoul_l()
  74.     {
  75.       digitalWrite(led_rd_l, HIGH);
  76.      
  77.       digitalWrite(led_wt_up_l_1, LOW);
  78.       digitalWrite(led_wt_up_l_2, LOW);
  79.       digitalWrite(led_wt_up_r_1, LOW);
  80.       digitalWrite(led_wt_up_r_2, LOW);
  81.       digitalWrite(led_wt_down_l_1, LOW);
  82.       digitalWrite(led_wt_down_l_2, LOW);
  83.       digitalWrite(led_wt_down_r_1, LOW);
  84.       digitalWrite(led_wt_down_r_2, LOW);
  85.       digitalWrite(led_ye_up, LOW);
  86.       digitalWrite(led_ye_mid,LOW);
  87.       digitalWrite(led_ye_down, LOW);
  88.       digitalWrite(led_gn, LOW);
  89.       digitalWrite(led_rd_r, LOW);
  90.  
  91.     }
  92.  
  93.  
  94. void startfoul_r()
  95.     {
  96.       digitalWrite(led_rd_r, HIGH);
  97.      
  98.       digitalWrite(led_wt_up_l_1, LOW);
  99.       digitalWrite(led_wt_up_l_2, LOW);
  100.       digitalWrite(led_wt_up_r_1, LOW);
  101.       digitalWrite(led_wt_up_r_2, LOW);
  102.       digitalWrite(led_wt_down_l_1, LOW);
  103.       digitalWrite(led_wt_down_l_2, LOW);
  104.       digitalWrite(led_wt_down_r_1, LOW);
  105.       digitalWrite(led_wt_down_r_2, LOW);
  106.       digitalWrite(led_ye_up, LOW);
  107.       digitalWrite(led_ye_mid,LOW);
  108.       digitalWrite(led_ye_down, LOW);
  109.       digitalWrite(led_gn, LOW);
  110.      
  111.     }
  112.  
  113.    
  114. void setup() {
  115.  
  116.  
  117. int start = digitalRead(button_start);
  118. int up = digitalRead(button_up);
  119. int down = digitalRead(button_down);
  120.  
  121. Serial.begin(9600);
  122. tft.begin();
  123.  
  124.     pinMode(startfoul_sensor_l, INPUT_PULLUP);
  125.     pinMode(startfoul_sensor_r, INPUT_PULLUP);
  126.  
  127.     pinMode(button_up, INPUT);
  128.     pinMode(button_down, INPUT);
  129.     pinMode(button_start, INPUT);
  130.  
  131.     pinMode(led_wt_up_l_1, OUTPUT);
  132.     pinMode(led_wt_up_l_2, OUTPUT);
  133.     pinMode(led_wt_up_r_1, OUTPUT);
  134.     pinMode(led_wt_up_r_2, OUTPUT);
  135.     pinMode(led_wt_down_l_1, OUTPUT);
  136.     pinMode(led_wt_down_l_2, OUTPUT);
  137.     pinMode(led_wt_down_r_1, OUTPUT);
  138.     pinMode(led_wt_down_r_2, OUTPUT);
  139.     pinMode(led_ye_up, OUTPUT);
  140.     pinMode(led_ye_mid, OUTPUT);
  141.     pinMode(led_ye_down, OUTPUT);
  142.     pinMode(led_gn, OUTPUT);
  143.     pinMode(led_rd_l, OUTPUT);
  144.     pinMode(led_rd_r, OUTPUT);
  145.  
  146.    
  147.   tft.setRotation(3);
  148.   tft.fillScreen(ILI9340_BLACK);
  149.   tft.setCursor(10, 80);
  150.   tft.setTextColor(ILI9340_WHITE);
  151.   tft.setTextSize(2);
  152.   tft.print("Projektarbeit 2017/ 2018");
  153.   tft.setCursor(10, 120);
  154.   tft.setTextColor(ILI9340_WHITE);
  155.   tft.setTextSize(2);
  156.   tft.print("Technikerschule Augsburg");
  157.   tft.setCursor(10, 160);
  158.   tft.setTextColor(ILI9340_WHITE);
  159.   tft.setTextSize(2);
  160.   tft.print("K16, Markus Starke:");
  161.   delay(5000);
  162.   tft.fillScreen(ILI9340_BLACK);
  163.  
  164. // Interruptroutinen
  165. attachInterrupt(digitalPinToInterrupt(startfoul_sensor_l), startfoul_l, RISING);
  166. attachInterrupt(digitalPinToInterrupt(startfoul_sensor_r), startfoul_r, RISING);
  167.  
  168. }
  169.  
  170.  
  171. void loop(){
  172.  
  173. while (!(digitalRead(button_start)))
  174. {
  175.    void menu();
  176.    
  177.     if(digitalRead(button_start))
  178.     int button_start1 = 1;
  179.    
  180.     if(digitalRead(button_up))
  181.     rundenzahl++;
  182.       tft.fillScreen(ILI9340_BLACK);
  183.    
  184.     if(digitalRead(button_down))
  185.     rundenzahl--;
  186.       tft.fillScreen(ILI9340_BLACK);
  187.  
  188.     tft.setCursor(165, 80);
  189.     tft.setTextColor(ILI9340_WHITE);
  190.     tft.setTextSize(3);
  191.     tft.print(rundenzahl);
  192.    
  193. }
  194.  
  195. int button_start2 = 0;
  196.  
  197. void  startsequenz();
  198.  
  199.  
  200. }
  201.  
  202.  
  203.  
  204. void startup() {
  205.  
  206.   tft.setRotation(3);
  207.   tft.fillScreen(ILI9340_BLACK);
  208.   tft.setCursor(10, 80);
  209.   tft.setTextColor(ILI9340_WHITE);
  210.   tft.setTextSize(2);
  211.   tft.print("Projektarbeit 2017/ 2018");
  212.   tft.setCursor(10, 120);
  213.   tft.setTextColor(ILI9340_WHITE);
  214.   tft.setTextSize(2);
  215.   tft.print("Technikerschule Augsburg");
  216.   tft.setCursor(10, 160);
  217.   tft.setTextColor(ILI9340_WHITE);
  218.   tft.setTextSize(2);
  219.   tft.print("K16, Markus Starke:");
  220.   delay(5000);
  221.  
  222. }
  223.  
  224.  
  225. void menu()
  226. {
  227.  
  228.   tft.setRotation(3);
  229.   tft.fillScreen(ILI9340_BLACK);
  230.  
  231.   tft.setCursor(20, 5);
  232.   tft.setTextColor(ILI9340_CYAN);
  233.   tft.setTextSize(3);
  234.   tft.print("Men"); tft.print((char)129);
  235.  
  236.  
  237.   tft.setCursor(20, 80);
  238.   tft.setTextColor(ILI9340_WHITE);
  239.   tft.setTextSize(3);
  240.   tft.print("Runden:");
  241.  
  242.   tft.setCursor(40, 140);
  243.   tft.setTextColor(ILI9340_WHITE);
  244.   tft.setTextSize(2);
  245.   tft.print("m/s");
  246.  
  247.   tft.setCursor(40, 205);
  248.   tft.setTextColor(ILI9340_WHITE);
  249.   tft.setTextSize(2);
  250.   tft.print("km/h");
  251.  
  252.   tft.setCursor(165, 80);
  253.   tft.setTextColor(ILI9340_WHITE);
  254.   tft.setTextSize(3);
  255.   tft.print(rundenzahl);
  256.  
  257.   tft.setCursor(252, 50);
  258.   tft.setTextColor(ILI9340_WHITE);
  259.   tft.setTextSize(3);
  260.   tft.print("+");
  261.  
  262.   tft.setCursor(252, 110);
  263.   tft.setTextColor(ILI9340_WHITE);
  264.   tft.setTextSize(3);
  265.   tft.print("-");
  266.  
  267.   tft.setCursor(200, 198);
  268.   tft.setTextColor(ILI9340_WHITE);
  269.   tft.setTextSize(2);
  270.   tft.print("START");
  271.  
  272.   tft.drawRect(20,130,80,40, ILI9340_RED);
  273.  
  274.   tft.drawRect(20,190,80,40, ILI9340_RED);
  275.  
  276.   tft.drawRect(220,40,80,40, ILI9340_RED);
  277.   tft.drawTriangle(220,40,260,20,300,40, ILI9340_RED);
  278.   tft.drawRect(220,100,80,40, ILI9340_RED);
  279.   tft.drawTriangle(220,140, 260,160, 300,140, ILI9340_RED);
  280.   tft.drawRect(160,180,140,50, ILI9340_RED);
  281.  
  282. }
  283.  
  284.  
  285. void startsequenz()
  286. {
  287.  
  288. startzeit = millis();
  289.  
  290.  
  291. if(millis() >= startzeit + 9000)
  292. {
  293.   digitalWrite(led_gn ,LOW);
  294.   rennzeit_start_l = millis();
  295.   rennzeit_start_r = millis();
  296.   sequenzende = 1;
  297. }
  298. else if(millis() >= startzeit + 6000)
  299. {
  300.   digitalWrite(led_ye_down, LOW);
  301.   digitalWrite(led_gn, HIGH);  
  302. }
  303.  
  304. else if(millis() >= startzeit + 5500)
  305. {
  306.   digitalWrite(led_ye_mid, LOW);
  307.   digitalWrite(led_ye_down, HIGH);  
  308. }
  309.  
  310. else if(millis() >= startzeit + 5000)
  311. {
  312.   digitalWrite(led_ye_up, LOW);
  313.   digitalWrite(led_ye_mid, HIGH);  
  314. }
  315.  
  316. else if(millis() >= startzeit + 4500)
  317. {
  318.   digitalWrite(led_wt_down_r_1, LOW);  
  319.   digitalWrite(led_wt_down_r_2, LOW);
  320.   digitalWrite(led_ye_up, HIGH);  
  321. }
  322.  
  323. else if(millis() >= startzeit + 3000)
  324. {
  325.   digitalWrite(led_wt_down_l_1, LOW);  
  326.   digitalWrite(led_wt_down_l_2, LOW);
  327.   digitalWrite(led_wt_down_r_1, HIGH);  
  328.   digitalWrite(led_wt_down_r_2, HIGH);  
  329. }
  330.  
  331. else if(millis() >= startzeit + 2000)
  332. {
  333.   digitalWrite(led_wt_up_r_1, LOW);  
  334.   digitalWrite(led_wt_up_r_2, LOW);  
  335.   digitalWrite(led_wt_down_l_1, HIGH);  
  336.   digitalWrite(led_wt_down_l_2, HIGH);  
  337. }
  338.  
  339. else if(millis() >= startzeit + 1000)
  340. {
  341.   digitalWrite(led_wt_up_l_1, LOW);  
  342.   digitalWrite(led_wt_up_l_2, LOW);
  343.   digitalWrite(led_wt_up_r_1, HIGH);  
  344.   digitalWrite(led_wt_up_r_2, HIGH);  
  345. }
  346.  
  347. else if(millis() >= startzeit)
  348. {
  349.   digitalWrite(led_wt_up_l_1, HIGH);  
  350.   digitalWrite(led_wt_up_l_2, HIGH);  
  351. }
  352. }
  353.  
  354. //void renndaten()
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364. /* Test für Speedmessung
  365.   lischra_1_state = digitalRead(lischra_1);
  366.   lischra_2_state = digitalRead(lischra_2);
  367.  
  368.  
  369.    if(lischra_1_state == 1){
  370.  
  371.       x = millis();
  372.      
  373.       while(lischra_2_state != 1) {
  374.        
  375.         lischra_2_state = digitalRead(lischra_2);
  376.         }
  377.      
  378.       y = millis();
  379.       z = (y - x);
  380.        
  381.       Serial.print(z);
  382.  
  383. }
  384. else{}
  385. */
Advertisement
Add Comment
Please, Sign In to add comment