Advertisement
nikolas77

camion grue

Feb 4th, 2021
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. //*** GESTION TOURELLE*****
  4.  
  5. int PotentiometreTourelle = A0;
  6. int ValPotentiometreTourelle;
  7. int ServoValTourelle;
  8. Servo moteurTourelle;
  9.  
  10. //***GESTION BRAS**********
  11.  
  12. int PotentiometreBras = A1;
  13. int ValPotentiometreBras;
  14. int ServoValBras;
  15. Servo moteurBras;
  16.  
  17. //***PHARES AVANT/ARRIERES***************
  18. const int BPPhares = 2;
  19. const int ledPhares = 3;
  20. int button_State_Phares = 0;
  21. int last_Button_State_Phares = 0;
  22. int led_State_Phares = 0;
  23.  
  24. //***GYROPHARES + DETRESSES**************
  25. int timeDelay = 500;
  26. bool buttonState = true;
  27. const int BPDetresse = 4;
  28. const int ledDetresse = 5;
  29. const int BPGyrophares = 6;
  30. const int ledGyrophares = 7;
  31.  
  32.  
  33. //***TREUIL******************************
  34. const int boutonMonteCable = 8;
  35. const int ledMonteCable = 9;
  36. const int boutonDescenteCable = 12;
  37. const int ledDescenteCable = 13;
  38.  
  39. int etatBoutonMonteCable = 0;
  40. int etatBoutonDescenteCable = 0;
  41.  
  42. void setup() {
  43.  
  44. pinMode(BPPhares,INPUT);
  45. pinMode(ledPhares, OUTPUT);
  46. pinMode(BPGyrophares,INPUT);
  47. pinMode(ledGyrophares, OUTPUT);
  48. pinMode(ledMonteCable, OUTPUT);
  49. pinMode(boutonMonteCable, INPUT);
  50. pinMode(ledDescenteCable, OUTPUT);
  51. pinMode(boutonDescenteCable, INPUT);
  52. pinMode(PotentiometreTourelle, INPUT);
  53. pinMode(PotentiometreBras, INPUT);
  54. moteurTourelle.attach(10);
  55. moteurBras.attach(11);
  56. }
  57.  
  58. void loop() {
  59.  
  60. GestionEclairages();
  61. GestionTreuil();
  62. GestionTourelle();
  63. GestionBras();
  64. }
  65. //*****************************
  66. void GestionEclairages(){
  67.  
  68. button_State_Phares = digitalRead(BPPhares);
  69.  
  70. if(button_State_Phares != last_Button_State_Phares){
  71.  
  72. if(button_State_Phares == 1) {
  73. if(led_State_Phares == 1) led_State_Phares = 0;
  74. else led_State_Phares = 1;
  75. }
  76. last_Button_State_Phares = button_State_Phares;
  77. }
  78. digitalWrite(ledPhares, led_State_Phares);
  79. delay(20);
  80.  
  81. if (digitalRead(BPGyrophares) == HIGH && buttonState)
  82. {
  83.  
  84. buttonState = !buttonState;
  85. while (!buttonState)
  86. {
  87. blink();
  88.  
  89. if (digitalRead(BPGyrophares) == HIGH && !buttonState)
  90. {
  91. digitalWrite(ledGyrophares, LOW);
  92. buttonState = !buttonState;
  93. delay(timeDelay);
  94. break;
  95. }
  96. }
  97. }
  98. }
  99.  
  100. void blink()
  101. {
  102. digitalWrite(ledGyrophares, HIGH);
  103. delay(timeDelay);
  104. digitalWrite(ledGyrophares, LOW);
  105. delay(timeDelay);
  106. }
  107. //***********************************
  108. void GestionTreuil(){
  109.  
  110. etatBoutonMonteCable = digitalRead(boutonMonteCable);
  111. etatBoutonDescenteCable = digitalRead(boutonDescenteCable);
  112.  
  113. if (etatBoutonMonteCable == HIGH) {
  114.  
  115. digitalWrite(ledMonteCable, HIGH);
  116. }
  117. else {
  118. digitalWrite(ledMonteCable, LOW);
  119. }
  120.  
  121. if (etatBoutonDescenteCable == HIGH) {
  122.  
  123. digitalWrite(ledDescenteCable, HIGH);
  124. }
  125. else {
  126. digitalWrite(ledDescenteCable, LOW);
  127. }
  128. }
  129. //****************************
  130. void GestionTourelle(){
  131.  
  132. ValPotentiometreTourelle = analogRead (PotentiometreTourelle);
  133. ServoValTourelle = map(ValPotentiometreTourelle, 0, 1023, 0, 180);
  134. moteurTourelle.write(ServoValTourelle);
  135. delay(5);
  136. }
  137.  
  138. //***************************
  139. void GestionBras(){
  140.  
  141. ValPotentiometreBras = analogRead (PotentiometreBras);
  142. ServoValBras = map(ValPotentiometreBras, 0, 1023, 0, 180);
  143. moteurBras.write(ServoValBras);
  144. delay(5);
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement