#include <Servo.h>
Servo servo0;
Servo servo1;
void setup() {
Serial.begin(115200);
pinMode(7, INPUT_PULLUP);
servo0.attach(5);
servo1.attach(6);
}
void loop() {
if (analogRead(A0) > 512 && analogRead(A1) == 512) {
for (int i = 0; i < 90; i++) {
servo0.write(90 - i);
servo1.write(90 + i);
}
}
if (analogRead(A0) < 512 && analogRead(A1) == 512) {
for (int i = 0; i < 90; i++) {
servo0.write(90 + i);
servo1.write(90 - i);
}
}
if (analogRead(A0) == 512 && analogRead(A1) < 512) {
for (int i = 0; i < 90; i++) {
servo0.write(90 + i);
servo1.write(90 + i);
}
}
if (analogRead(A0) == 512 && analogRead(A1) > 512) {
for (int i = 0; i < 90; i++) {
servo0.write(90 - i);
servo1.write(90 - i);
}
}
if (analogRead(A0) == 512 && analogRead(A1) == 512) {
for (int i = 0; i < 90; i++) {
servo0.write(90);
servo1.write(90);
}
}
Serial.print("A0:");
Serial.print(analogRead(A0));
Serial.print(" A1:");
Serial.println(analogRead(A1));
delay(200);
}