// the number of the LED pin
const int ledPin = 4;
const int ledPin2 = 15;
// int LED_BUILTIN = 2; // LED_BUILTIN already preexistent defined
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int ledChannel2 = 1;
const int resolution = 8; // equals 0 - 255 increments
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// Led without PWM
// pinMode(ledPin, OUTPUT);
// internal LED
pinMode(LED_BUILTIN, OUTPUT);
// PWM: configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
ledcSetup(ledChannel2, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
ledcAttachPin(ledPin2, ledChannel2);
}
void loop() {
/*// put your main code here, to run repeatedly:
digitalWrite(ledPin, HIGH); // turn the LED on
delay(500); // wait for 500 milliseconds
digitalWrite(ledPin, LOW); // turn the LED off
delay(500);
*/
digitalWrite(LED_BUILTIN, HIGH);
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle += 5){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
ledcWrite(ledChannel2, 255-dutyCycle);
delay(50);
}
delay (1000);
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle -=5){
// changing the LED brightness with PWM
ledcWrite(ledChannel, dutyCycle);
ledcWrite(ledChannel2, 255-dutyCycle);
delay(50);
}
digitalWrite(LED_BUILTIN, LOW);
delay (1000);
}