Created
February 10, 2020 09:51
-
-
Save gresan-gits/c423be564b76fb6a33e138a4002dcf55 to your computer and use it in GitHub Desktop.
ESP32 PWM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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