Here is my code
Code: Select all
#define LEDC_HS_TIMER LEDC_TIMER_0
#define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE
#define LEDC_HS_CH0_GPIO (32)
#define LEDC_HS_CH0_CHANNEL 0
#define LEDC_HS_CH1_GPIO (33)
#define LEDC_HS_CH1_CHANNEL 1
#define LEDC_LS_TIMER LEDC_TIMER_1
#define LEDC_LS_MODE LEDC_LOW_SPEED_MODE
#define LEDC_LS_CH2_GPIO (26)
#define LEDC_LS_CH2_CHANNEL 2
#define LEDC_LS_CH3_GPIO (0)
#define LEDC_LS_CH3_CHANNEL 3
#define LEDC_TEST_CH_NUM (4)
ledc_timer_config_t ledc_timer;
ledc_channel_config_t ledc_channel[LEDC_TEST_CH_NUM];
/**************************************************************************//**
\brief
\details
*******************************************************************************/
void initLeds()
{
/*
* Prepare and set configuration of timers
* that will be used by LED Controller
*/
ledc_timer.duty_resolution = LEDC_TIMER_13_BIT;
ledc_timer.freq_hz = 5000;
ledc_timer.speed_mode = LEDC_HS_MODE;
ledc_timer.timer_num = LEDC_HS_TIMER;
// Set configuration of timer0 for high speed channels
ledc_timer_config(&ledc_timer);
// Prepare and set configuration of timer1 for low speed channels
ledc_timer.speed_mode = LEDC_LS_MODE;
ledc_timer.timer_num = LEDC_LS_TIMER;
ledc_timer_config(&ledc_timer);
ledc_channel[0].channel = (ledc_channel_t)LEDC_HS_CH0_CHANNEL;
ledc_channel[0].duty = 4000;
ledc_channel[0].gpio_num = LEDC_HS_CH0_GPIO;
ledc_channel[0].speed_mode = LEDC_HS_MODE;
ledc_channel[0].timer_sel = LEDC_HS_TIMER;
ledc_channel[0].intr_type = LEDC_INTR_DISABLE;
ledc_channel[1].channel = (ledc_channel_t)LEDC_HS_CH1_CHANNEL;
ledc_channel[1].duty = 4000;
ledc_channel[1].gpio_num = LEDC_HS_CH1_GPIO;
ledc_channel[1].speed_mode = LEDC_HS_MODE;
ledc_channel[1].timer_sel = LEDC_HS_TIMER;
ledc_channel[1].intr_type = LEDC_INTR_DISABLE;
ledc_channel[2].channel = (ledc_channel_t)LEDC_LS_CH2_CHANNEL;
ledc_channel[2].duty = 4000;
ledc_channel[2].gpio_num = LEDC_LS_CH2_GPIO;
ledc_channel[2].speed_mode = LEDC_HS_MODE;
ledc_channel[2].timer_sel = LEDC_HS_TIMER;
ledc_channel[2].intr_type = LEDC_INTR_DISABLE;
ledc_channel[3].channel = (ledc_channel_t)LEDC_LS_CH3_CHANNEL;
ledc_channel[3].duty = 4000;
ledc_channel[3].gpio_num = LEDC_LS_CH3_GPIO;
ledc_channel[3].speed_mode = LEDC_LS_MODE;
ledc_channel[3].timer_sel = LEDC_LS_TIMER;
ledc_channel[3].intr_type = LEDC_INTR_DISABLE;
// Set LED Controller with previously prepared configuration
for (int ch = 0; ch < LEDC_TEST_CH_NUM; ch++) {
ledc_channel_config(&ledc_channel[ch]);
}
// Initialize fade service.
ledc_fade_func_install(0);
Thanks,
Naem