Bonjour à tous,
J’ai un petit problème avec un servo-moteur. J’ai fait un programme pour lorsque j’appuie sur un bouton le servo-moteur tourne à 180° et reviens à sa position.
Il marche très bien. Mais lorsque l’on à appuyé et que le programme à fini, le servo-moteur grésille.
Quel est le problème ?
Merci d’avance pour vos réponses.
je vous transmets ci-dessous mon programme :
#include <Servo.h>
Servo myservo; // create servo object to control a servo
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 12 ; // the number of the LED pin
*int buttonState = 0; *
void setup() {
- myservo.attach(9); // attaches the servo on pin 9 to the servo object*
- pinMode(buttonPin, INPUT);*
- pinMode(ledPin, OUTPUT);*
- int pos = 0;*
- Serial.begin(9600);*
}
void loop() {
int pos = 0;
- buttonState = digitalRead(buttonPin);*
if (buttonState == HIGH) {
- for (pos = 0 ; pos <= 180; pos = pos+1)*
- { // goes from 0 degrees to 180 degrees*
- // in steps of 1 degree*
- myservo.write(pos); // tell servo to go to position in variable ‘pos’*
- delay(15); // waits 15ms for the servo to reach the position*
- }*
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees - myservo.write(pos); // tell servo to go to position in variable ‘pos’*
- delay(15); // waits 15ms for the servo to reach the position*
}
- digitalWrite(ledPin, HIGH);*
- pos=0;*
- myservo.write(pos);*
- delay(3000);*
} else { - // turn LED off:*
- digitalWrite(ledPin, LOW);*
}
}
Nicolas