// --- Configuration Constants ---
const int pwmPin = 13;
const int frequency = 5000;
const uint8_t resolution = 8; // 0-255 range
const uint32_t dutyCycle = 128; // ~50% for 8-bit
// ========================== SETUP ==========================
void setup() {
Serial.begin(115200); // Optional: for debug messages
Serial.println("ESP32 Fixed PWM Example (Pin-Based API)");
// 1. Configure and attach the PWM pin using LEDC
ledcAttach(pwmPin, frequency, resolution);
Serial.printf("Attached PWM to GPIO %d\n", pwmPin);
// 2. Set the fixed PWM duty cycle using ledcWrite with the PIN number
ledcWrite(pwmPin, dutyCycle); // Using pwmPin here
Serial.printf("Set fixed duty cycle %u on pin %d\n", dutyCycle,
pwmPin);
}
// ========================== LOOP ==========================
void loop() {
// PWM is handled by hardware. Nothing needed here for fixed output.
delay(1000);
}