#include <Servo.h> // Include the Servo library
Servo servo1; // Create a servo object for servo 1
Servo servo2; // Create a servo object for servo 2
void setup() {
servo1.attach(9); // Attach the first servo to pin 9
servo2.attach(10); // Attach the second servo to pin 10
}
void loop() {
// Sweep both servos from 0 to 180 degrees and back
for (int pos = 0; pos <= 180; pos++) {
servo1.write(pos); // Move servo1 to the position 'pos'
servo2.write(180 - pos); // Move servo2 to the opposite position
delay(15); // Wait for the servos to reach the position
}
for (int pos = 180; pos >= 0; pos--) {
servo1.write(pos); // Move servo1 back to the position 'pos'
servo2.write(180 - pos); // Move servo2 to the opposite position
delay(15); // Wait for the servos to reach the position
}
}