#define pinLed 14
#define freq 1800 // pwm frequency
// #define ledChannel 0 // OLD API
#define resolution 8 // 8 bit resolution (0 - 255)
#define ledOff 0
#define ledOn 250 // 255 is the maximum value, max_duty = pow(2, resolution) - 1
int value = 0; // pwm value
void setup() {
// ledcSetup(ledChannel, freq, resolution); // configure pwm OLD API
// ledcAttachPin(ledPin, ledChannel); // attach channel to pin OLD API
ledcAttach(ledPin, freq, resolution); // configure pwm to the pin (channel is auto selected)
}
void loop() {
//blink
// ledcWrite(ledChannel, ledOff); // Turn off led OLD API
ledcWrite(ledPin, ledOff); // Turn off led
delay(1000); // Wait a second
// ledcWrite(ledChannel, ledOn); // Turn on led OLD API
ledcWrite(ledPin, ledOn); // Turn on led
delay(1000); // Wait a second
// ledcWrite(ledChannel, ledOff); // ... OLD API
ledcWrite(ledPin, ledOff); // ...
delay(1000);
// ledcWrite(ledChannel, ledOn); // OLD API
ledcWrite(ledPin, ledOn);
delay(1000);
//dimm
for (value = ledOn; value > ledOff; value --) { //decrease the light by decreasing "value"
// ledcWrite(ledChannel, value); // OLD API
ledcWrite(ledPin, value);
delay(20);
}
for (value = ledOff; value < ledOn; value ++) { //increase the light by increasing "value"
// ledcWrite(ledChannel, value); // OLD API
ledcWrite(ledPin, value);
delay(20);
}
}
Hello there, thanks for this repository.
With the new API for ESP32, the code should be modified this way :
https://docs.espressif.com/projects/arduino-esp32/en/latest/api/ledc.html
Best regards