// the number of the LED pin
const int ledPin1 = 27; // GPIO27
const int ledPin2 = 26; // GPIO27
// setting PWM properties
const int freq = 1000;
const int ledChannel1 = 0;
const int ledChannel2 = 1;
const int resolution = 8;
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel1, freq, resolution);
ledcSetup(ledChannel2, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin1, ledChannel1);
ledcAttachPin(ledPin2, ledChannel2);
}
void loop(){
// increase the LED brightness
for(int dutyCycle1 = 0; dutyCycle1 <= 50; dutyCycle1++){
// changing the LED brightness with PWM
ledcWrite(ledChannel1, dutyCycle1);
ledcWrite(ledChannel2, dutyCycle1);
delay(15);
}
// decrease the LED brightness
for(int dutyCycle = 50; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
ledcWrite(ledChannel1, dutyCycle);
ledcWrite(ledChannel2, dutyCycle);
delay(15);
}
}