#include <ESP32Servo.h>
const int steeringPin = 34; // GPIO pin for the steering angle sensor (e.g., potentiometer or rotary encoder)
const int motorPin = 13; // GPIO pin to control the servo motor
Servo cameraServo; // Create a servo object to control the camera
void setup() {
Serial.begin(115200); // Initialize serial communication
cameraServo.attach(motorPin); // Attach the servo motor to the pin
cameraServo.write(90); // Set the camera to the neutral position (90 degrees)
}
void loop() {
int steeringValue = analogRead(steeringPin); // Read the steering wheel sensor value (0-4095)
// Map the steering value (0-4095) to an angle for the servo (0-180 degrees)
int mappedAngle = map(steeringValue, 0, 4095, 0, 180);
// Set the camera position based on the steering angle
cameraServo.write(mappedAngle);
// Print the steering angle and camera position for debugging
Serial.print("Steering Value: ");
Serial.print(steeringValue);
Serial.print(" -> Mapped Camera Angle: ");
Serial.println(mappedAngle);
delay(100); // Add a small delay for stability
}