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 38 39
|
#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
{
Y=y-Yo; // position angulaire "après tare"
P=Y; // determination de la position angulaire souhaitée (equation temporaire)
{
s.write(P); // tell servo to go to position in variable 'pos'
A=s.read();
}
}
}
Serial.print("y= "); // print y adc value
Serial.println(y);
Serial.print(" a= ");
Serial.println(A); // affichage de la position de A en fin de déplacement
delay(100);
} |
Partager