I am having trouble compiling the code; getting error, can you suggest a solution?
<analogWriteArduino: 1.8.9 (Windows 10), Board: "SparkFun ESP32 Thing, 80MHz, Default, 921600, None" : error: 'analogWrite' was not declared in this scope> analogWrite(PWMA, abs(motorSpeed)); ^'analogWrite' was not declared in this scope
I have this in the code…
//the motor will be controlled by the motor A pins on the motor driver
const int AIN1 = 13; //control pin 1 on the motor driver for the right motor
const int AIN2 = 12; //control pin 2 on the motor driver for the right motor
const int PWMA = 11; //speed control pin on the motor driver for the right motor
int switchPin = 7; //switch to turn the robot on and off
//VARIABLES
int motorSpeed = 0; //starting speed for the motor
void setup() {
pinMode(switchPin, INPUT_PULLUP); //set this as a pullup to sense whether the switch is flipped
//set the motor control pins as outputs
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMA, OUTPUT);
2 Answers
Hi
esp32 does nto use analogWrite() for PWM ..
It uses
ledcAttachPin(GPIO, channel)
https://randomnerdtutorials.com/esp32-pwm-arduino-ide/