-
-
Save shima-529/f37402d6e10f358b2035b83dff37eb5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 逐一値実行版 | |
#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