Advertisement
nikolas77

PN

Mar 10th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. //*****************************************************************PASSAGE A NIVEAU************************************************************************************
  2. //*********************************************************************************************************************************************************************
  3. //Un bouton poussoir pour fermer le passage, Un autre bouton poussoir pour l'ouvrir avec chacun une led pour signaler l'etat du passage (mode manuel)
  4. //Un capteur de distance pour la fermeture (mode automatique)
  5. //Un capteur de distance pour l'ouverture (mode automatique)
  6. //Un interrupteur pour basculer du mode automatique au mode manuel
  7. //Deux servomoteurs pour les barriéres
  8. //Le passage a niveau est ouvert au demarrage du programme
  9. //*********************************************************************************************************************************************************************
  10. #include <Servo.h> //bibliotéque servomoteur
  11.  
  12. int bouton1 = 3; //bouton fermeture passage a niveau
  13. int bouton2 = 2; //bouton ouverture passage a niveau
  14.  
  15. int etatbouton1 = 0;
  16. int etatbouton2 = 0;
  17.  
  18. bool boutonState = false;
  19.  
  20. int Led1 = 6; //led fermeture passage a niveau
  21. int Led2 = 7; //led ouverture passage a niveau
  22. int Led3 = 4; //led signaux passage a niveau
  23.  
  24. #define Broche_Echo 12
  25. #define Broche_Trigger 11
  26.  
  27. int MesureMaxi = 300;
  28. int MesureMini = 3;
  29. long Duree;
  30. long Distance;
  31.  
  32. int AutoManuel = 8;
  33.  
  34. Servo monservo; //servomoteur barriéres
  35.  
  36.  
  37. void setup(){
  38.  
  39. Serial.begin(115200);
  40.  
  41. pinMode(bouton1, INPUT); //bouton fermeture passage a niveau
  42. pinMode(bouton2, INPUT); //bouton ouverture passage a niveau
  43.  
  44. pinMode(AutoManuel, INPUT);
  45.  
  46. pinMode(Broche_Trigger, OUTPUT);
  47. pinMode(Broche_Echo, INPUT);
  48.  
  49. pinMode(Led1, OUTPUT); //led fermeture passage a niveau
  50. pinMode(Led2, OUTPUT); //led ouverture passage a niveau
  51. pinMode(Led3, OUTPUT); //led signaux passage a niveau
  52. digitalWrite(Led2, HIGH); //led ouverture passage a niveau
  53. monservo.attach(5); //servomoteur barriéres
  54. }
  55.  
  56. void loop()
  57. {
  58. //*****************************MANUEL****************************************************
  59. if(digitalRead(AutoManuel) == HIGH && !boutonState)
  60. {
  61.  
  62. etatbouton1 = digitalRead (bouton1);
  63. etatbouton2 = digitalRead (bouton2);
  64.  
  65. if (etatbouton1==HIGH) {
  66. digitalWrite(Led1, HIGH);
  67. digitalWrite(Led2, LOW);
  68. digitalWrite(Led3, HIGH);
  69. delay(800);
  70. digitalWrite(Led3, LOW);
  71. delay(800);
  72. digitalWrite(Led3, HIGH);
  73. delay(800);
  74. digitalWrite(Led3, LOW);
  75. delay(800);
  76. digitalWrite(Led3, HIGH);
  77. monservo.write (0);
  78. digitalWrite(Led3, HIGH);
  79. delay(800);
  80. digitalWrite(Led3, LOW);
  81. delay(800);
  82. digitalWrite(Led3, HIGH);
  83. delay(800);
  84. digitalWrite(Led3, LOW);
  85. delay(800);
  86. digitalWrite(Led3, HIGH);
  87.  
  88. }
  89. if (etatbouton2==HIGH) {
  90. digitalWrite(Led1, LOW);
  91. digitalWrite(Led2, HIGH);
  92. digitalWrite(Led3, LOW);
  93. monservo.write (90);
  94. boutonState = !boutonState;
  95. delay(500);
  96. }
  97. }
  98.  
  99. //*******************************AUTOMATIQUE**********************************************
  100. if(digitalRead(AutoManuel) == HIGH && boutonState)
  101. {
  102. digitalWrite(Broche_Trigger, LOW);
  103. delayMicroseconds(2);
  104. digitalWrite(Broche_Trigger, HIGH);
  105. delayMicroseconds(10);
  106. digitalWrite(Broche_Trigger, LOW);
  107.  
  108. Duree = pulseIn(Broche_Echo, HIGH);
  109.  
  110. Distance = Duree*0.034/2;
  111.  
  112. if (Distance >= MesureMaxi || Distance <= MesureMini) {
  113.  
  114. digitalWrite(Led1, HIGH);
  115. digitalWrite(Led2, LOW);
  116. digitalWrite(Led3, HIGH);
  117. delay(800);
  118. digitalWrite(Led3, LOW);
  119. delay(800);
  120. digitalWrite(Led3, HIGH);
  121. delay(800);
  122. digitalWrite(Led3, LOW);
  123. delay(800);
  124. digitalWrite(Led3, HIGH);
  125. monservo.write (0);
  126. digitalWrite(Led3, HIGH);
  127. delay(800);
  128. digitalWrite(Led3, LOW);
  129. delay(800);
  130. digitalWrite(Led3, HIGH);
  131. delay(800);
  132. digitalWrite(Led3, LOW);
  133. delay(800);
  134. digitalWrite(Led3, HIGH);
  135. Serial.println("fermer");
  136. }
  137. else
  138. {
  139. digitalWrite(Led1, LOW);
  140. digitalWrite(Led2, HIGH);
  141. digitalWrite(Led3, LOW);
  142. monservo.write (90);
  143. Serial.println("ouvert");
  144. boutonState = !boutonState;
  145. delay(500);
  146. }
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement