#include <ESP32Servo.h>
Servo myservo;
int pos = 0;
int redLedPin = 2;
int greenLedPin = 4;
void setup() {
Serial.begin(9600);
myservo.attach(15);
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
}
void loop() {
for (pos = 45; pos <= 180; pos += 45) {
myservo.write(pos);
delay(500);
if (pos >= 35 && pos <= 60) {
digitalWrite(redLedPin, HIGH);
digitalWrite(greenLedPin, LOW);
} else if (pos >= 70 && pos <= 90) {
digitalWrite(greenLedPin, HIGH);
digitalWrite(redLedPin, LOW);
Serial.print("Servo повернут на ");
Serial.print(pos);
Serial.println(" градусов.");
} else {
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, LOW);
}
}
}