I just compiled the sketch from the Adafruit page for an ESP32 (DOIT ESP32 DEVKIT V1) and it compiled without any errors or warnings. What model ESP32 did you select?
Close but (EDIT to add: "typically,") the motor moves when the two pins are different. If you change IN1 to HIGH that means that the motor will move in reverse when IN2 is LOW. Now '255' means stopped and '0' means full speed. An easy way to make it more understandable is:
ledcWrite() is the function used to write PWM in ESP32s. analogWrite() wouldn´t work. Take a look at the code you´ve posted at first: it uses the following sequence:
ledcAttachPin(Motor,0); // to attach PWM channel 0 to pin 21
ledcSetup(0,4000,8); // configures channel 0 with 4000 Hz frequency and 8 bit resolution (that means 2^8 values --> min=0, max=255)
ledcWrite(0,i); // writes a PWM value between 0 and 255 to channel 0
To solve your problem you can do one of the following things:
Learn how to use PWM in ESP32 "old fashioned way" like above; OR
On the Arduino IDE, update ESP32 board version to 2.0.2. This way, it will accept analogWrite(). Adafruit and @johnwasser ´s code will then work for you; OR
install and use the library that you´ve mentioned in #11, which probably just converts analogWrite() format to ledcWrite() format.
Number (3) will need you to learn how to use the library anyway. So, if you have some time and patience, it´s better going to (1). But if you want faster result, (2) looks better.
It's like I said, in one case I increase the value so that the speed decreases, and in the other case I increase the value so that the speed decreases, but why? The logic is that 255 is always the highest speed, as with l298n.
The main statement of @johnwasser declaration is this one:
That means when IN1 is HIGH and IN2 is LOW, motor rotates to one side. When IN1 is LOW and IN2 is HIGH, motor rotates to the other side. If you want to control speed, then you change the HIGH side for an analogWrite() with the value that you want.
The rest of his statement was related to this:
In this case, both channels are HIGH at the same time and the motor will stop. Changing 255 for 0 would move the motor full speed (EDIT: because de other side is already HIGH).
In this case I would like to take a look in your code that is working. Would you mind to share it?
My motor works fine when I control it via serial monitor, but not when I control it via BLE. When I do it via BLE it only works in one direction, via serial monitor it works in both directions.