1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| #include <Servo.h>
Servo s; // create servo object to control a servo
unsigned int A; // affichage de la position du moteur
unsigned int P;
unsigned int pos; //Variable moteur
int y; // y axis variable
unsigned int Yo; // y de réfenrence, voiture immobile pour effectuer ce qui
équivault à une tare
unsigned int Y;
void setup() {
Serial.begin(57600); // opens serial port, sets data rate to 57600 bps
s.attach(9); // attaches the servo on pin 9 to the servo object
Yo=analogRead(2);
Serial.print("Yo = ");
Serial.println(Yo);
}
void loop() {
{
y = analogRead(2); // read the first analog input pin
Serial.print("y= "); // print y adc value
Serial.println(y);
{
Y=y-Yo; // position angulaire "après tare"
P=Y+5 // determination de la position angulaire souhaitée (equation temporaire)
{
for( pos=A ; pos=P ; pos +=1 )
s.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits Xms for the servo to reach the position
A=s.read();
Serial.print(" a= ");
Serial.println(A); // affichage de la position de A en fin de déplacement
}}}
delay(100);
} |
Partager