Skip to content

Instantly share code, notes, and snippets.

@shima-529
Created January 30, 2021 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shima-529/efce7d2c4dfa2e5b96b168d42c98db32 to your computer and use it in GitHub Desktop.
Save shima-529/efce7d2c4dfa2e5b96b168d42c98db32 to your computer and use it in GitHub Desktop.
// WAIT版
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include "sdkconfig.h"
void app_main(void) {
ledc_timer_config_t tconfig = {
.speed_mode = LEDC_HIGH_SPEED_MODE,
.duty_resolution = LEDC_TIMER_10_BIT,
.timer_num = LEDC_TIMER_0,
.freq_hz = 1000,
.clk_cfg = LEDC_AUTO_CLK
};
ledc_timer_config(&tconfig);
ledc_channel_config_t cconfig = {
.gpio_num = 2,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = 1024,
.hpoint = 0
};
ledc_channel_config(&cconfig);
ledc_fade_func_install(ESP_INTR_FLAG_LEVEL1);
ledc_set_fade_with_step(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 1024, 16, 10);
/* ledc_fade_start(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT); */
while(1) {
ledc_fade_start(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, LEDC_FADE_WAIT_DONE);
vTaskDelay(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment