// #include <esp32-hal-ledc.h>

// the number of the LED pin
const int ledPin = 23;  // GPIO23


// setting PWM properties
const int freq = 5000;    // se genera un ciclo cada 1/5000 sec = 200 usec
const int ledchannel = 0; // hace uso del Timer 0, ver tabla documento
const int resolution = 8; // divide ciclo en 2**resolution -> 256 valores
 

float dutyCycle; // valor

void setup(){

  // configure LED PWM functionalitites
  ledcSetup(ledchannel, freq, resolution);
  
  // attach the channel to the GPIO to be controlled
  ledcAttachPin(ledPin, ledchannel);

  Serial.begin(115200);
  
}
 
void loop(){

  dutyCycle = 0.5;  // valor inicial 
  ledcWrite(ledchannel, dutyCycle * (2^resolution -1)); 
  Serial.printf("Valor dutyCycle: %3.0f % \n", 100*dutyCycle); 
  delay(2000);
  
  dutyCycle = 0.0;  // se genera un PWM 0 => se apaga el led  
  ledcWrite(ledchannel, dutyCycle * (2^resolution -1)); 
  Serial.printf("Valor dutyCycle: %3.0f % \n", 100*dutyCycle); 
  delay(2000);
}