C:\Users\jamsa\OneDrive\Desktop\sketch_jan28a\sketch_jan28a.ino: In function 'void setup()':
sketch_jan28a:16:24: error: 'analogWrite' was not declared in this scope
analogWrite (enA, 255);
^
exit status 1
'analogWrite' was not declared in this scope
Index error: could not find referenced tool name=avrdude version=6.3.0-arduino17or18 packager=arduino
Index error: could not find referenced tool name=avrdude version=6.3.0-arduino17or18 packager=arduino
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
If you do not want to update your esp-arduino core then look at the example code
for the LEDcSoftwareFade example. It shows how to control analog output (pwm).
Play around with that and that should get you going.
As already stated, PWM in ESP32 works different than in Arduino.
You should configure a channel (ledcSetup), then associate this channel to a pin (ledcAttachPin) and then write the "speed" to the channel (ledcWrite).
My board here doesn´t have an Enable pin (or it´s hide and always on) so I write the speed directly into the channel that is receiving energy. For example:
ledcSetup(15, 5000, 10); //Configures channel 15 with 5000 Hz frequency and 10 bits resolution
At 10 bit resolution, you can set "speed" from 0 to 1024. So 50% would be 512. However, it may be not enough to your motor. I suggest to begin with higher values (like 900) and then decrease untill you see the limit where it still moves.
You need to detach the pin from the channel each time you change directions. So, the code parts should be like this:
//setup
ledcSetup(15, 5000, 10);
//loop
//Move forward
ledcDetachPin(in2);
digitalWrite(in2, LOW);
ledcAttachPin(in1, 15); //Attach PWM signal (channel 15) to pin in1
ledcWrite(15,800); //Sends a signal to channel 15
delay(1000);
//Move backward
ledcDetachPin(in1);
digitalWrite(in1, LOW);
ledcAttachPin(in2, 15);
ledcWrite(15,800);
delay(1000);
//STOP
ledcDetachPin(in1);
ledcDetachPin(in2);
digitalWrite(ET, LOW);
digitalWrite(DF, LOW);
delay(1000);
}