#include <Servo.h>
// Create servo objects
Servo servo1;
Servo servo2;
void setup() {
// Attach the servo motors to PWM pins
servo1.attach(9); // Pin 8 for Servo 1
servo2.attach(10); // Pin 11 for Servo 2
// Move servos to initial positions
servo1.write(0); // Set Servo 1 to 0 degrees
servo2.write(90); // Set Servo 2 to 90 degrees
delay(1000); // Wait for the servo to move
}
void loop() {
// Move Servo 1 from 0 to 180 degrees and back
for (int pos = 0; pos <= 180; pos++) {
servo1.write(pos); // Tell servo to go to 'pos' position
delay(15); // Wait for the servo to reach the position
}
for (int pos = 180; pos >= 0; pos--) {
servo1.write(pos); // Tell servo to go to 'pos' position
delay(15); // Wait for the servo to reach the position
}
// Move Servo 2 from 90 to 180 degrees and back
for (int pos = 90; pos <= 180; pos++) {
servo2.write(pos); // Tell servo to go to 'pos' position
delay(15); // Wait for the servo to reach the position
}
for (int pos = 180; pos >= 90; pos--) {
servo2.write(pos); // Tell servo to go to 'pos' position
delay(15); // Wait for the servo to reach the position
}
}