Compiling error
Posted: 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
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
}