#include <Servo.h>
Servo servo1;
Servo servo2;
int hor = A1;//servo1
int ver = A0;//servo2
void setup() {
// put your setup code here, to run once:
servo1.attach(11);
servo2.attach(9);
pinMode(8, INPUT);
pinMode(hor, INPUT);
pinMode(ver, INPUT);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int horiVal = map(analogRead(hor),0,1023,-90,90);
int vertiVal = map(analogRead(ver),0,1023,-90,90);
servo1.write(horiVal);
if(vertiVal==0){
servo2.write(horiVal);
}
else if(horiVal>=vertiVal){
servo2.write(horiVal-vertiVal);
}
else{
servo2.write(0);
}
}