MrDiy-Audio-Notifier
MrDiy-Audio-Notifier copied to clipboard
analogWrite not work for esp32, using ledc
on esp32, analogWrite function is not avaliable.
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
....
//setup()
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(LED_Pin, ledChannel);
pinMode(LED_Pin, OUTPUT);
...
//
void updateLEDBrightness(int brightness_percentage)
{
#ifdef LED_Pin
#ifdef ESP32
ledcWrite(ledChannel, (int)brightness_percentage * 255 / 100);
#else
analogWrite(LED_Pin, (int)brightness_percentage * 255 / 100);
#endif
#endif
}
this will be work fine
Thanks for the update, merge done ;)