// define LED pin
int ledPin = 4;
//define PWM parameters
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8; //resoluion 8bit =256 values
void setup() {
// This function is used to setup the LEDC channel frequency and resolution.
ledcSetup(ledChannel, freq, resolution);
// This function is used to attach the pin to the LEDC channel.
ledcAttachPin(ledPin, ledChannel);
}
void loop(){
// increase the LED brightness
for(int i = 0; i <= 255; i=i+10){
// This function is used to set duty for the LEDC channel.
ledcWrite(ledChannel, i);
delay(15);
}
// decrease the LED brightness
for(int i = 255; i >= 0; i=i-10){
// changing the LED brightness with PWM
ledcWrite(ledChannel, i);
delay(15);
}
}