3#ifdef ARDUINO_ESP32_DEV
6#include "platforms/esp/esp_version.h"
7#include "driver/ledc.h"
8#include "esp32-hal-ledc.h"
13#if !ESP_IDF_VERSION_4_OR_HIGHER
14FL_WEAK void analogWrite(uint8_t pin,
int value) {
16 static bool channels_setup[16] = {
false};
17 static uint8_t channel_counter = 0;
20 static uint8_t pin_to_channel[40] = {255};
21 if (pin_to_channel[pin] == 255) {
22 pin_to_channel[pin] = channel_counter++;
23 if (channel_counter > 15) channel_counter = 0;
26 uint8_t channel = pin_to_channel[pin];
29 if (!channels_setup[channel]) {
30 ledcSetup(channel, 5000, 8);
31 ledcAttachPin(pin, channel);
32 channels_setup[channel] =
true;
36 ledcWrite(channel, value);