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:
parent
2ce1aa54ed
commit
a9944f5a47
|
@ -14,7 +14,7 @@ int enable1Pin = 14;
|
|||
const int freq = 30000;
|
||||
const int pwmChannel = 0;
|
||||
const int resolution = 8;
|
||||
int dutyCycle = 200;
|
||||
int dutyCycle = 250;
|
||||
|
||||
void setup() {
|
||||
// sets the pins as outputs:
|
||||
|
@ -28,6 +28,8 @@ void setup() {
|
|||
// attach the channel to the GPIO to be controlled
|
||||
ledcAttachPin(enable1Pin, pwmChannel);
|
||||
|
||||
ledcWrite(pwmChannel, dutyCycle);
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
// testing
|
||||
|
@ -59,15 +61,4 @@ void loop() {
|
|||
digitalWrite(motor1Pin2, LOW);
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue