// Servo Sweep example for the ESP32
// https://wokwi.com/arduino/projects/323706614646309460
#include <ESP32Servo.h>
#define ldr1 32
#define ldr2 33
const int servoPin = 18;
Servo servo;
void setup() {
servo.attach(servoPin, 500, 2400);
pinMode(ldr1, INPUT);
pinMode(ldr2, INPUT);
}
int pos = servo.read();
void loop() {
int ldrValue1 = analogRead(ldr1); // Read the value of LDR1
int ldrValue2 = analogRead(ldr2); // Read the value of LDR2
if (ldrValue1>ldrValue2){
servo.write(pos-120);
}
else if (ldrValue2>ldrValue1){
servo.write(pos+120);
}
}