Page 1 of 1

Compiling error

Posted: Mon Jun 23, 2025 7:57 pm
by ted123
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
}

Re: Compiling error

Posted: Tue Jun 24, 2025 3:57 am
by lbernstone
ledcSetup was from an older version of the API.
Doco
examples

Re: Compiling error

Posted: Tue Jun 24, 2025 6:25 am
by ted123
And a new version is ?

Re: Compiling error

Posted: Wed Jun 25, 2025 3:28 pm
by lbernstone
Current stable is v3.2.0

Re: Compiling error

Posted: Fri Jun 27, 2025 2:03 pm
by lsdlsd88
easiest way is install last 2.x version on esp32 board manager

Re: Compiling error

Posted: Thu Jul 31, 2025 5:41 pm
by RandomInternetGuy
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

Re: Compiling error

Posted: Fri Aug 01, 2025 5:28 am
by horace99
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