No matching function for call to 'Pwm::attach(const byte&, int, bool)'

Hi all.
The sketch below works well on the announcer‘s wokwi.

I copied that and got compiling error of:
no matching function for call to 'Pwm::attach(const byte&, int, bool)'

how to fix?
Thanks
Adam

 // ESP32-ESP32S2-AnalogWrite
// https://github.com/Dlloydev/ESP32-ESP32S2-AnalogWrite

#include <pwmWrite.h>

const byte pwm100Hz20DutyPin = 19;
const byte pwm100Hz30DutyPin = 18;
const byte pwm100Hz50DutyPin = 5;
const byte pwm25Hz50DutyPin = 21;
Pwm pwm = Pwm();

// pwm.write(pwmPin, duty, frequency, resolution);

void setup() {
  pwm.write(pwm100Hz20DutyPin, 205, 100, 10);
  pwm.write(pwm100Hz30DutyPin, 307, 100, 10);
  pwm.write(pwm100Hz50DutyPin, 512, 100, 10);

  pwm.attach(pwm25Hz50DutyPin, 4, true);
  pwm.write(pwm25Hz50DutyPin, 512, 25, 10);
}

void loop() {
  delay(10); // speeds up the simulation
}

Arduino:1.8.19 (Windows 7), 开发板:"ESP32 Dev Module, Disabled, Disabled, Huge APP (3MB No OTA/1MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None, Disabled"

C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_oct12f\sketch_oct12f.ino: In function 'void setup()':

sketch_oct12f:23:39: error: no matching function for call to 'Pwm::attach(const byte&, int, bool)'

   pwm.attach(pwm25Hz50DutyPin, 4, true);

                                       ^

In file included from C:\Users\HUA.DELLV-PC\Documents\Arduino\sketch_oct12f\sketch_oct12f.ino:8:

C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\ESP32-ESP32S2-AnalogWrite-main\src/pwmWrite.h:80:13: note: candidate: 'uint8_t Pwm::attach(int)'

     uint8_t attach(int pin);                 // attach pin to next free channel

             ^~~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\ESP32-ESP32S2-AnalogWrite-main\src/pwmWrite.h:80:13: note:   candidate expects 1 argument, 3 provided

C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\ESP32-ESP32S2-AnalogWrite-main\src/pwmWrite.h:81:13: note: candidate: 'uint8_t Pwm::attach(int, int)'

     uint8_t attach(int pin, int ch);         // attach to specified ch

             ^~~~~~

C:\Users\HUA.DELLV-PC\Documents\Arduino\libraries\ESP32-ESP32S2-AnalogWrite-main\src/pwmWrite.h:81:13: note:   candidate expects 2 arguments, 3 provided

exit status 1

no matching function for call to 'Pwm::attach(const byte&, int, bool)'

Seems to be complaining about the third param..
Which by looking at it, I'm thinking this would be true to invert it..
And yes, the WokWi does in fact compile fine..
Something must have changed in the lib, looking through pwmWrite.h, I'm thinking you want to use..

pwm.attachInvert(pwm25Hz50DutyPin, 4);

instead..

good luck.. ~q

1 Like

Look in pwmWrite.h for the attach function:

    uint8_t attach(int pin);                 // attach pin to next free channel
    uint8_t attach(int pin, int ch);         // attach to specified ch

You'll see there's no overload that includes a third parameter of type bool. So why are you supplying one?

1 Like

Thanks.

Thanks.

are there any idea that ESP32 PWM be able to vary frequency or not?

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