// LED pin number
const int ledPin = 16; // 16 corresponds to GPIO16
// setting PWM properties
const int frequency = 5000; // setting frequency to 5KHz
const int ledChannel = 0; // using led channel 0
const int resolution = 8; // using 8 bit resolution to control the brightness from 0 to 255.
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel, frequency, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
//code to loop the fucntionality 3 times and stop.
int loop = 0;
while(loop < 3){
// increase the LED brightness
for(int i = 0; i <= 255; i++){ // where i is the dutyCycle of the PWM signal.
// changing the LED brightness with PWM
ledcWrite(ledChannel, i);
delay(15);
}
// decrease the LED brightness
for(int i = 255; i >= 0; i--){
// changing the LED brightness with PWM
ledcWrite(ledChannel, i);
delay(15);
}
loop++;
}
}
void loop(){
// To loop continuously place the code here.
}