Caught the error that was making me think I broke my ESP32 dev boards. The ledcWrite() duty cycle was not being set on the pwmChannel. This is intended for LEDS but I don't know if it matters that it's being used for a variable speed DC motor.

This commit is contained in:
Matt McWilliams 2024-01-30 00:12:36 -05:00
parent 2ce1aa54ed
commit a9944f5a47
1 changed files with 3 additions and 12 deletions

View File

@ -14,7 +14,7 @@ int enable1Pin = 14;
const int freq = 30000; const int freq = 30000;
const int pwmChannel = 0; const int pwmChannel = 0;
const int resolution = 8; const int resolution = 8;
int dutyCycle = 200; int dutyCycle = 250;
void setup() { void setup() {
// sets the pins as outputs: // sets the pins as outputs:
@ -28,6 +28,8 @@ void setup() {
// attach the channel to the GPIO to be controlled // attach the channel to the GPIO to be controlled
ledcAttachPin(enable1Pin, pwmChannel); ledcAttachPin(enable1Pin, pwmChannel);
ledcWrite(pwmChannel, dutyCycle);
Serial.begin(115200); Serial.begin(115200);
// testing // testing
@ -59,15 +61,4 @@ void loop() {
digitalWrite(motor1Pin2, LOW); digitalWrite(motor1Pin2, LOW);
delay(1000); delay(1000);
// Move DC motor forward with increasing speed
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
while (dutyCycle <= 255){
ledcWrite(pwmChannel, dutyCycle);
Serial.print("Forward with duty cycle: ");
Serial.println(dutyCycle);
dutyCycle = dutyCycle + 5;
delay(500);
}
dutyCycle = 200;
} }