• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

analogWrite defintion

Q&A Forum › Category: ESP32 › analogWrite defintion
0 Vote Up Vote Down
Michael Nicholas asked 6 years ago

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);
Question Tags: analogWrite
2 Answers
0 Vote Up Vote Down
DK answered 6 years ago

Hi
esp32 does nto use analogWrite() for PWM ..
It uses

ledcAttachPin(GPIO, channel)


https://randomnerdtutorials.com/esp32-pwm-arduino-ide/

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Michael.
Exactly what DK said.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.