Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<Servo.h>
- Servo monServo1; // Moteur1
- Servo monServo2; // Moteur2
- int posiMoteur1 = 90; // Position Moteur 1
- int posiMoteur2 = 90; // Position Moteur 2
- int sensMoteur1 = HIGH; //Sens de rotation qui alterne à chaque appui
- int sensMoteur2 = HIGH; //Sens de rotation qui alterne à chaque appui
- int buttonPin1 = 7; // Pin bouton poussoir 1
- int buttonPin2 = 8; // Pin bouton poussoir 2
- int buttonState1; // Etat bouton poussoir 1
- int buttonState2; // Etat bouton poussoir 2
- void setup() {
- // put your setup code here, to run once:
- monServo1.attach(2); // Moteur 1 sur PIN 2
- monServo2.attach(4); // Moteur 2 sur PIN 4
- pinMode(buttonPin1, INPUT);
- pinMode(buttonPin2, INPUT);
- monServo1.write(posiMoteur1); // Initialisation position moteur 1 à 90deg
- monServo2.write(posiMoteur2); // Initialisation position moteur 2 à 90deg
- }
- void loop() {
- // put your main code here, to run repeatedly:
- buttonState1 = digitalRead (buttonPin1); // Lecture bouton 1
- buttonState2 = digitalRead (buttonPin2); // Lecture bouton 2
- if (buttonState1 == HIGH) //Si on appuie sur Bouton 1 alors...
- { while (buttonState1 == HIGH) //boucle tant que le bouton est appuyé
- {if (sensMoteur1 == HIGH) //incrémente ou decrément suivant valeur de sensMoteur1
- posiMoteur1 +=1;
- else
- posiMoteur1 -=1;
- monServo1.write(posiMoteur1); //applique nouvelle position
- delay (15); //petit delai
- buttonState1 = digitalRead (buttonPin1); //relecture du bouton poussoir
- }
- sensMoteur1 = !sensMoteur1; //a la fin de la boucle, le sens du moteur est inversé
- }
- if (buttonState2 == HIGH) //Si on appuie sur bouton 2 alors
- { while (buttonState2 == HIGH) //boucle tant que le bouton est appuyé
- {if (sensMoteur2 == HIGH) //incrémente ou decrément suivant valeur de sensMoteur1
- posiMoteur2 +=1;
- else
- posiMoteur2 -=1;
- monServo2.write(posiMoteur2); //applique nouvelle position
- delay (15); //petit delai
- buttonState2 = digitalRead (buttonPin2); //relecture du bouton poussoir
- }
- sensMoteur2 = !sensMoteur2; //a la fin de la boucle, le sens du moteur est inversé
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement