#include<Servo.h>
Servo motor1;
Servo motor1h;
Servo motor2;
Servo motor2h;
void setup() {
Serial.begin(9600);
}
void loop() {
//top left motor,left joystick(vertical)
int js1=analogRead(A0);
motor1.attach(5);
int i1=motor1.read();
// Serial.println(i1);
if(js1>512){
// Serial.println("up");
// Serial.println(i);
if(i1<=180){
i1=i1-1;
motor1.write(i1);
delay(10);
}
}
else if(js1<512){
if(i1>=0){
i1=i1+1;
motor1.write(i1);
delay(10);
}
// Serial.println("down");
}
//bottom left motor,left joystick(horizontal)
int js1h=analogRead(A2);
motor1h.attach(11);
int i1h=motor1h.read();
if(js1h>512){
// Serial.println("up");
if(i1h<=180){
i1h=i1h-1;
motor1h.write(i1h);
delay(10);
}
}
else if(js1h<512){
if(i1h>=0){
i1h=i1h+1;
motor1h.write(i1h);
delay(10);
}
// Serial.println("down");
}
//top right motor,right joystick(vertical)
int js2=analogRead(A1);
motor2.attach(3);
// Serial.println(js2);
int i2=motor2.read();
if(js2>512){
if(i2<=180){
i2=i2-1;
motor2.write(i2);
delay(10);
}
}
else if(js2<512){
if(i2>=0){
i2=i2+1;
motor2.write(i2);
delay(10);
}
}
//bottom right motor,right joystick(horizontal)
int js2h=analogRead(A3);
motor2h.attach(10);
int i2h=motor2h.read();
if(js2h>512){
if(i2h<=180){
i2h=i2h-1;
motor2h.write(i2h);
delay(10);
}
}
else if(js2h<512){
if(i2h>=0){
i2h=i2h+1;
motor2h.write(i2h);
delay(10);
}
}
}