Is there an Equivalent to LEDC functions from ESP32 / Arduino? (for PWM)

Tags: #<Tag:0x00007fe224632758> #<Tag:0x00007fe2246323c0> #<Tag:0x00007fe2246320f0>


Hi, I am porting some of my code from ESP32 to Argon, and have run into a problem.

My ESP32 code uses the LEDC functions from the Arduino IDE.


// declare PWM vars
int FanSpeedPin = D8;
int fanSpeed = 255;

// setting PWM properties
int freq = 15000;
int fanChannel = 0;
int resolution = 8;

ledcSetup(fanChannel, freq, resolution);
ledcAttachPin(FanSpeedPin, fanChannel);
ledcWrite(fanChannel, fanSpeed);   

I use these to control the speed of a fan via PWM… these functions sure make it easy.

Is there an equivalent in the Particle cloud IDE?

If not, are there any examples of setting the frequency and duty cycle?

I would like to set the Frequency to 15 kHz, and then be able to change the duty cycle as needed.

Thanks so much for any assistance.


@NDParticleDev, have you looked at the documentation on the PWM and associated functions?

Here is an example from those docs:

pinMode(D1, OUTPUT);     // sets the pin as output
analogWriteResolution(D1, 12); // sets analogWrite resolution to 12 bits
analogWrite(D1, 3000, 1000); // 3000/4095 = ~73% duty cycle at 1kHz


Wow… i did a lot of Googling… but did not find a reference to this.

This looks great!

Thank you so much peekay123…

This community is awesone… great people here.