Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analogWrite not work for esp32, using ledc #15

Open
0neday opened this issue Apr 16, 2022 · 1 comment
Open

analogWrite not work for esp32, using ledc #15

0neday opened this issue Apr 16, 2022 · 1 comment

Comments

@0neday
Copy link
Contributor

0neday commented Apr 16, 2022

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

@schmurtzm
Copy link
Owner

Thanks for the update, merge done ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants