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/f37402d6e10f358b2035b83dff37eb5f to your computer and use it in GitHub Desktop.
Save shima-529/f37402d6e10f358b2035b83dff37eb5f to your computer and use it in GitHub Desktop.
// 逐一値実行版
#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);
uint32_t duty = 1024;
while(1) {
vTaskDelay(20 / portTICK_PERIOD_MS);
duty -= 16;
if( duty == 0 ) duty = 1024;
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0, duty);
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_TIMER_0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment