Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. #include<Servo.h>
  2.  
  3. Servo monServo1; // Moteur1
  4. Servo monServo2; // Moteur2
  5. int posiMoteur1 = 90; // Position Moteur 1
  6. int posiMoteur2 = 90; // Position Moteur 2
  7. int sensMoteur1 = HIGH; //Sens de rotation qui alterne à chaque appui
  8. int sensMoteur2 = HIGH; //Sens de rotation qui alterne à chaque appui
  9. int buttonPin1 = 7; // Pin bouton poussoir 1
  10. int buttonPin2 = 8; // Pin bouton poussoir 2
  11. int buttonState1; // Etat bouton poussoir 1
  12. int buttonState2; // Etat bouton poussoir 2
  13.  
  14. void setup() {
  15. // put your setup code here, to run once:
  16. monServo1.attach(2); // Moteur 1 sur PIN 2
  17. monServo2.attach(4); // Moteur 2 sur PIN 4
  18. pinMode(buttonPin1, INPUT);
  19. pinMode(buttonPin2, INPUT);
  20. monServo1.write(posiMoteur1); // Initialisation position moteur 1 à 90deg
  21. monServo2.write(posiMoteur2); // Initialisation position moteur 2 à 90deg
  22. }
  23.  
  24. void loop() {
  25. // put your main code here, to run repeatedly:
  26. buttonState1 = digitalRead (buttonPin1); // Lecture bouton 1
  27. buttonState2 = digitalRead (buttonPin2); // Lecture bouton 2
  28.  
  29. if (buttonState1 == HIGH) //Si on appuie sur Bouton 1 alors...
  30. { while (buttonState1 == HIGH) //boucle tant que le bouton est appuyé
  31. {if (sensMoteur1 == HIGH) //incrémente ou decrément suivant valeur de sensMoteur1
  32. posiMoteur1 +=1;
  33. else
  34. posiMoteur1 -=1;
  35. monServo1.write(posiMoteur1); //applique nouvelle position
  36. delay (15); //petit delai
  37. buttonState1 = digitalRead (buttonPin1); //relecture du bouton poussoir
  38. }
  39. sensMoteur1 = !sensMoteur1; //a la fin de la boucle, le sens du moteur est inversé
  40. }
  41.  
  42. if (buttonState2 == HIGH) //Si on appuie sur bouton 2 alors
  43. { while (buttonState2 == HIGH) //boucle tant que le bouton est appuyé
  44. {if (sensMoteur2 == HIGH) //incrémente ou decrément suivant valeur de sensMoteur1
  45. posiMoteur2 +=1;
  46. else
  47. posiMoteur2 -=1;
  48. monServo2.write(posiMoteur2); //applique nouvelle position
  49. delay (15); //petit delai
  50. buttonState2 = digitalRead (buttonPin2); //relecture du bouton poussoir
  51. }
  52. sensMoteur2 = !sensMoteur2; //a la fin de la boucle, le sens du moteur est inversé
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement