MrDiy-Audio-Notifier icon indicating copy to clipboard operation
MrDiy-Audio-Notifier copied to clipboard

analogWrite not work for esp32, using ledc

Open 0neday opened this issue 2 years ago • 1 comments

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

0neday avatar Apr 16 '22 12:04 0neday

Thanks for the update, merge done ;)

schmurtzm avatar Apr 18 '22 11:04 schmurtzm