Advertisement
Guest User

Untitled

a guest
May 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. int z1; //Indice 1 = Table Gauche
  2. int z1precedent;
  3. int z1variation;
  4. int zmax = 0;
  5. int z2; //Indice 2 = Table Droite
  6. int z2precedent;
  7. int z2variation;
  8. int z3; //Indice 3 = Filet
  9. int z3precedent;
  10. int z3variation;
  11. int z3max = 0;
  12. int PinLedGauche = 2;
  13. int PinLedDroite = 3;
  14. int test = 0;
  15. unsigned long t1max;
  16. unsigned long t2max;
  17. unsigned long timer;
  18. String Serveur;
  19. String JoueurRenvoieBalle;
  20. void setup()
  21. {
  22. Serial.begin(9600); // sets the serial port to 9600
  23. pinMode(PinLedGauche, OUTPUT);
  24. pinMode(PinLedDroite, OUTPUT);
  25. digitalWrite(PinLedGauche, LOW);
  26. digitalWrite(PinLedDroite, LOW);
  27. Serveur = "Gauche";
  28. }
  29.  
  30. void loop()
  31. {
  32. //SERVICE
  33. switch(Serveur)
  34. {
  35. case "Gauche":
  36. DetectionTable();
  37. timerService = millis();
  38. while(millis() - timerService < 10000)
  39. {
  40. if(DetectionTable() = "Droite");
  41. {
  42. JOUEUR DROITE +1; //JOUEUR GAUCHE PERDU
  43. }
  44. if(DetectionTable() = "Gauche");
  45. {
  46. timerService = millis();
  47. while(millis() - timerService > 2000)
  48. {
  49. if(DetectionTable() = "Gauche")
  50. {
  51. JOUEUR DROITE +1; //JOUEUR GAUCHE PERDU
  52. }
  53. if(DetectionTable() = "Droite") //SERVICE REUSSI LE POINT CONTINU
  54. {
  55. //CODER ECHANGE JUSQU'A FAUTE D'UN JOUEUR
  56.  
  57. }
  58. }
  59. }
  60. else
  61. {
  62. JOUEUR DROITE +1; //JOUEUR GAUCHE PERDU
  63. }
  64. }
  65. case "Droite":
  66. DetectionTable();
  67. timerService = millis();
  68. while(millis() - timerService < 10000)
  69. {
  70. if(DetectionTable() = "Gauche");
  71. {
  72. JOUEUR GAUCHE +1; //JOUEUR DROITE PERDU
  73. }
  74. if(DetectionTable() = "Droite");
  75. {
  76. timerService = millis();
  77. while(millis() - timerService > 2000)
  78. {
  79. if(DetectionTable() = "Droite")
  80. {
  81. JOUEUR GAUCHE +1; //JOUEUR DROITE PERDU
  82. }
  83. if(DetectionTable() = "Gauche") //SERVICE REUSSI LE POINT CONTINU
  84. {
  85. //CODER ECHANGE JUSQU'A FAUTE D'UN JOUEUR
  86.  
  87. }
  88. }
  89. }
  90. }
  91. }
  92.  
  93. String DetectionTable()
  94. {
  95. z1precedent = z1;
  96. z2precedent = z2;
  97. z3precedent = z3;
  98. z1 = analogRead(A0);
  99. z2 = analogRead(A1);
  100. z3 = analogRead(A2);
  101. z1variation = abs(z1 - z1precedent);
  102. z2variation = abs(z2 - z2precedent);
  103. z3variation = abs(z3 - z3precedent);
  104. if((z1variation) > 12 || (z2variation) > 12)
  105. {
  106. t1max = millis();
  107. while(millis() - t1max < 350)
  108. {
  109. if(z3variation > 10) // ON ETUDIE Z3 (FILET) QUE LORS DU SERVICE, IL FAUDRA RAJOUTER UN PARAMETRE A CETTE FONCTION
  110. {
  111. z3max += z3variation;
  112. }
  113. zmax += (z1variation - z2variation);
  114. z1precedent = z1;
  115. z2precedent = z2;
  116. z3precedent = z3;
  117. z1 = analogRead(A0);
  118. z2 = analogRead(A1);
  119. z3 = analogRead(A2);
  120. z1variation = abs(z1 - z1precedent);
  121. z2variation = abs(z2 - z2precedent);
  122. z3variation = abs(z3 - z3precedent);
  123. //Serial.println(z3max);
  124. if(zmax > 0)
  125. {
  126. digitalWrite(PinLedGauche, HIGH);
  127. digitalWrite(PinLedDroite, LOW);
  128. return "Gauche";
  129. }
  130. if(zmax <0)
  131. {
  132. digitalWrite(PinLedGauche, LOW);
  133. digitalWrite(PinLedDroite, HIGH);
  134. return "Droite";
  135. }
  136. if(z3max > 100)
  137. {
  138. return "Let";
  139. }
  140. else
  141. {
  142. return "Rien";
  143. }
  144. }
  145. }
  146. zmax = 0;
  147. z3max = 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement