#define LED_PIN 22

// setting PWM properties
const int LED_PWM_FREQ = 5000;
const int LED_PWM_CHANNEL = 0;
const int LED_PWM_RESOLUTION = 8;


void setup() {

  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");

  // configure LED PWM functionalitites
  ledcSetup(LED_PWM_CHANNEL, LED_PWM_FREQ, LED_PWM_RESOLUTION);
  // attach the channel to the GPIO to be controlled
  ledcAttachPin(LED_PIN, LED_PWM_CHANNEL);
}

void loop() {

  // increase the LED brightness
  for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle+=16){   
    // changing the LED brightness with PWM
    ledcWrite(LED_PWM_CHANNEL, dutyCycle);
    delay(50);
  }

  delay(1000);

  // decrease the LED brightness
  for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle-=16){
    // changing the LED brightness with PWM
    ledcWrite(LED_PWM_CHANNEL, dutyCycle);   
    delay(50);
  }
}