#include <Servo.h>
int servoPin=9;
int ledPin=13;
int servoPos=90;
Servo task1;
void setup() {
Serial.begin(9600);
task1.attach(servoPin);
pinMode(ledPin, OUTPUT);
}
void loop() {
for (int angle = 0; angle <= 180; angle++) {
task1.write(angle); // Set the servo to the current angle
digitalWrite(ledPin, HIGH); // Turn LED on
delay(15); // Wait for the servo to reach the position
digitalWrite(ledPin, LOW); // Turn LED off
delay(15); // Brief delay before the next position
}
// Sweep from 180 to 0 degrees
for (int angle = 180; angle >= 0; angle--) {
task1.write(angle); // Set the servo to the current angle
digitalWrite(ledPin, HIGH); // Turn LED on
delay(15); // Wait for the servo to reach the position
digitalWrite(ledPin, LOW); // Turn LED off
delay(15); // Brief delay before the next position
}
}