Compiling error

ted123
Posts: 5
Joined: Mon Jun 23, 2025 7:45 pm

Compiling error

Postby ted123 » Mon Jun 23, 2025 7:57 pm

Hi I'm trying to run this program but I have a compiling error.
How to fix that ?
exit status 1
'ledcSetup' was not declared in this scope

Code: Select all

#include <Arduino.h>
#include <math.h>

const int pwmPin = 16;      // Example PWM pin
const int pwmFrequency = 5000; // Example frequency
const int pwmResolution = 8;  // Example resolution (0-255)
const int ledcChannel = 0; // Example channel

const float amp = 127.5; // Half of the max value (255/2)
const float stp = 0.1;  // Step size for the sine wave
float i = 0;

void setup() {
  ledcSetup(ledcChannel, pwmFrequency, pwmResolution);
  ledcAttachPin(pwmPin, ledcChannel);
}

void loop() {
  int dutyCycle = (int)(amp + amp * sin(stp * i)); // Calculate the duty cycle
  ledcWrite(ledcChannel, dutyCycle);             // Write the duty cycle
  i += 1; // Increment the iterator
  delay(10); // Add a small delay to control the speed
}

lbernstone
Posts: 1131
Joined: Mon Jul 22, 2019 3:20 pm

Re: Compiling error

Postby lbernstone » Tue Jun 24, 2025 3:57 am

ledcSetup was from an older version of the API.
Doco
examples

ted123
Posts: 5
Joined: Mon Jun 23, 2025 7:45 pm

Re: Compiling error

Postby ted123 » Tue Jun 24, 2025 6:25 am

And a new version is ?

lbernstone
Posts: 1131
Joined: Mon Jul 22, 2019 3:20 pm

Re: Compiling error

Postby lbernstone » Wed Jun 25, 2025 3:28 pm

Current stable is v3.2.0

lsdlsd88
Posts: 3
Joined: Mon Mar 10, 2025 10:08 am

Re: Compiling error

Postby lsdlsd88 » Fri Jun 27, 2025 2:03 pm

easiest way is install last 2.x version on esp32 board manager

RandomInternetGuy
Posts: 81
Joined: Fri Aug 11, 2023 4:56 am

Re: Compiling error

Postby RandomInternetGuy » Thu Jul 31, 2025 5:41 pm

easiest way is install last 2.x version on esp32 board manager
Best way is to modernize the code so you're not always having to find outdated versions of things.

ledCsetup's demise was documented long ago.

https://docs.espressif.com/projects/ard ... o_3.0.html

horace99
Posts: 34
Joined: Mon Oct 14, 2024 10:38 am

Re: Compiling error

Postby horace99 » Fri Aug 01, 2025 5:28 am

have a look at the section on LEDC in https://docs.espressif.com/projects/ard ... o_3.0.html which gives details the new APIs

Who is online

Users browsing this forum: Applebot, Bytespider, ChatGPT-User and 1 guest