'ledcSetup' was not declared in this scope

Hello everyone,
I don't know if I chose the best category,
I looked for a category that included WOKWI, but I couldn't find it.

When trying to help in
(ESP 32 IR Sensor control Motor) I came across a situation that I couldn't solve.

I copied the code from the topic and pasted it into the WOKWI simulator, selecting ESP32.

When compiling, the error appeared:

sketch.ino:11:3: error: 'ledcSetup' was not declared in this scope
11 | ledcSetup(0, 5000, 8); // channel 0, 5kHz, 8-bit resolution
| ^~~~~~~~~

and other errors.

I found it strange, because the syntax of line 11 was correct.
I searched the WEB and didn't find anything that would help me with the error.

So I looked for an example of WOKWI that used this function, and I found some.
I selected one, and ran it. It didn't give an error.

So I copied line 11 of the OP's code and pasted it into the example.
It gave the same type of error when running.

I removed the line but the line was blank. I ran it and it gave an error.
I removed the blank line and it ran normally.

In setup() and included a blank line and ran it. It gave an error.
I removed the line and it ran correctly.

In loop() and included a blank line and ran it. It gave an error.
I removed the line and it ran correctly.

Here's the link to the simulator.

I would like someone to run this example in the simulator and then add a
blank line anywhere in the setup() or loop() and check if it gives an error.

Thanks in advance.

One guess at what's going on:

the online examples are already compiled and when you launch the simulation they use the archived code that might have been compiled with an old version of the libraries.

if you insert a blank line and hit compile, the file has been modified and so a new compilation is launched, with newest versions of the libraries.

As Espressif modified ledC in between version 2 and version 3 of their core, may be that's the issue you meet with the new library

see their Migration from 2.x to 3.0 - - — Arduino ESP32 latest documentation which mentions the changes to ledC including the ledcSetup

LEDC

The LEDC API has been changed in order to support the Peripheral Manager and make it easier to use, as LEDC channels are now automatically assigned to pins. For more information about the new API, check LED Control (LEDC).

Removed APIs

  • ledcSetup
  • ledcAttachPin

New APIs

  • ledcAttach used to set up the LEDC pin (merged ledcSetup and ledcAttachPin functions).
  • ledcOutputInvert used to attach the interrupt to a timer using arguments.
  • ledcFade used to set up and start a fade on a given LEDC pin.
  • ledcFadeWithInterrupt used to set up and start a fade on a given LEDC pin with an interrupt.
  • ledcFadeWithInterruptArg used to set up and start a fade on a given LEDC pin with an interrupt using arguments.

Changes in APIs

  • ledcDetachPin renamed to ledcDetach.
  • In all functions, input parameter channel has been changed to pin.
4 Likes

Thank you for your reply.

To avoid using an already compiled project, I copied the code from the WOKWI topic that I found on the WEB and created a new project in WOKWI and pasted the code I copied.

And it compiled correctly.

But when inserting any new line, the error occurred.

I believe that the "owners" of WOKWI need to make changes to this API.

Thank you again.

I had gotten the same error using my ESP32 WROOM, what i did to solve it was check the Github repository for the library and checked all the functions. the function "ledcSetup" along with some others were not found, so i used the functions that were given there and it worked.

1 Like

Post #2 is the Solution, mark it so.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.