#include <ESP32Servo.h>
// Pin tanimlari / Pin definitions
// UYARI: Klasik ESP32'de GPIO1 = UART0 TX / Warning: GPIO1 is UART0 TX
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
const int POT_PIN = 1; // S2/S3: ADC1_CH0 / S2/S3: ADC1_CH0
#else
const int POT_PIN = 34; // Klasik ESP32 input-only / Classic input-only
#endif
const int SERVO_PIN = 18;
Servo myServo;
void setup() {
Serial.begin(115200);
// 12-bit ADC sabitle / Force 12-bit ADC
analogReadResolution(12);
// Servo timer ayari / Servo timer setup
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
myServo.setPeriodHertz(50); // SG90 icin 50 Hz / 50 Hz for SG90
myServo.attach(SERVO_PIN, 500, 2400); // Pulse 500-2400us / Pulse 500-2400us
Serial.println("Servo kontrol hazir!");
}
void loop() {
int potValue = analogRead(POT_PIN);
// 0-4095 -> 0-180 derece / 0-4095 -> 0-180 degrees
int angle = map(potValue, 0, 4095, 0, 180);
myServo.write(angle);
Serial.print("Pot: ");
Serial.print(potValue);
Serial.print(" -> Aci: ");
Serial.println(angle);
delay(15); // Servo yerlesme bekleme / Servo settle delay
}