Skip to content

Instantly share code, notes, and snippets.

@gresan-gits
Created February 10, 2020 09:51
Show Gist options
  • Save gresan-gits/c423be564b76fb6a33e138a4002dcf55 to your computer and use it in GitHub Desktop.
Save gresan-gits/c423be564b76fb6a33e138a4002dcf55 to your computer and use it in GitHub Desktop.
ESP32 PWM
const int ledPin = 16;
const int ledPin2 = 17;
const int ledPin3 = 5;
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup() {
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
ledcAttachPin(ledPin2, ledChannel);
ledcAttachPin(ledPin3, ledChannel);
}
void loop() {
int dutyCycle;
for (dutyCycle = 0; dutyCycle <= 255; dutyCycle++) {
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
for ( dutyCycle = 255; dutyCycle >= 0; dutyCycle--) {
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment