const int pwmPin = 18;  // GPIO18 (D18)

const int freq = 1000;   // 1 kHz
const int resolution = 8;

void setup() {
  ledcAttach(pwmPin, freq, resolution);
}

void loop() {

  for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) {
    ledcWrite(pwmPin, dutyCycle);
    delay(15);
  }

  for (int dutyCycle = 255; dutyCycle >= 0; dutyCycle--) {
    ledcWrite(pwmPin, dutyCycle);
    delay(15);
  }
}