Created
April 26, 2021 15:32
-
-
Save makersenses/51bdf8d03feab536c393e7f8dc2c2a62 to your computer and use it in GitHub Desktop.
15.esp32_motor_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 motor_AL = 4; | |
const int motor_AR = 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(motor_AL, ledChannel); | |
pinMode(motor_AL, OUTPUT); | |
pinMode(motor_AR, OUTPUT); | |
digitalWrite(motor_AR, LOW); | |
} | |
void loop(){ | |
// increase the LED brightness | |
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){ | |
ledcWrite(ledChannel, dutyCycle); | |
delay(15); | |
} | |
// decrease the LED brightness | |
for(int 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