/* Ledc fade example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/xtensa_api.h"
#include "freertos/queue.h"
#include "driver/ledc.h"
#include "esp_attr.h"
#include "esp_err.h"
/*
* About this example
* 1. init LEDC module:
* a. You need to set the timer of LEDC first, this decide the frequency and resolution of PWM.
* b. You need to set the LEDC channel you want to use, and bind with one of the timers.
*
* 2. You can install a default fade function, then you can use fade APIs.
*
* 3. You can also set a target duty directly without fading.
*
* 4. This example use GPIO18/19/4/5 as LEDC ouput, and it will change the duty repeatedly.
*
*
*/
#define LEDC_IO_0 (2)
esp_err_t app_main()
{
ledc_timer_config_t ledc_timer = {
//set timer counter bit number
.bit_num = LEDC_TIMER_13_BIT,
//set frequency of pwm
.freq_hz = 5000,
//timer mode,
.speed_mode = LEDC_HIGH_SPEED_MODE,
//timer index
.timer_num = LEDC_TIMER_0
};
ledc_timer_config(&ledc_timer);
ledc_channel_config_t ledc_channel = {
//set LEDC channel 0
.channel = LEDC_CHANNEL_0,
//set the duty for initialization.(duty range is 0 ~ ((2**bit_num)-1)
.duty = 0,
//GPIO number
.gpio_num = LEDC_IO_0,
//GPIO INTR TYPE, as an example, we enable fade_end interrupt here.
.intr_type = LEDC_INTR_FADE_END,
//set LEDC mode, from ledc_mode_t
.speed_mode = LEDC_HIGH_SPEED_MODE,
//set LEDC timer source, if different channel use one timer,
//the frequency and bit_num of these channels should be the same
.timer_sel = LEDC_TIMER_0
};
//set the configuration
ledc_channel_config(&ledc_channel);
//initialize fade service.
ledc_fade_func_install(0);
while(1) {
printf("LEDC fade up\n");
ledc_set_fade_with_time(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 1000, 2000);
ledc_fade_start(LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT);
vTaskDelay(3000 / portTICK_PERIOD_MS);
printf("LEDC fade down\n");
ledc_set_fade_with_time(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 0, 2000);
ledc_fade_start(LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT);
vTaskDelay(3000 / portTICK_PERIOD_MS);
/*printf("LEDC set duty without fade\n");
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 1000);
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
vTaskDelay(2000 / portTICK_PERIOD_MS);
printf("LEDC set duty without fade\n");
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 0);
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
vTaskDelay(2000 / portTICK_PERIOD_MS);*/
}
}
noticeable
- 粉丝: 9
- 资源: 45
最新资源
- OpenCV开发资源.txt
- YOLO v3 的 PyTorch 实现,包括训练和测试,并可适用于用户定义的数据集.zip
- 安卓开发学习资源.txt
- yolo v3 物体检测系统的 Go 实现.zip
- YOLO v1 pytorch 实现.zip
- python爱心代码高级.txt
- Yolo for Android 和 iOS - 用 Kotlin 和 Swift 编写的实时移动深度学习对象检测.zip
- Yolnp 是一个基于 YOLO 检测车牌的项目.zip
- Unity Barracuda 上的 Tiny YOLOv2.zip
- Ultralytics YOLO iOS App 源代码可用于在你自己的 iOS 应用中运行 YOLOv8.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈