const int inputPin = A0;
const int leftPin = 6;
const int rightPin = 5;
#include <Servo.h>
Servo Lservo; // create servo object to control a servo
Servo Rservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int Lpos = 0; // variable to store the servo position
int Rpos = 0; // variable to store the servo position
void setup() {
Lservo.attach(leftPin); // attaches the servo on pin 9 to the servo object
Rservo.attach(rightPin); // attaches the servo on pin 9 to the servo object
Serial.begin(115200);
}
void loop() {
long pos;
pos = analogRead(inputPin);
Lservo.write(int(pos*180/1024)); // tell servo to go to position in variable 'pos'
Rservo.write(180-int(pos*180/1024)); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}