/****************************************************************************** * 作者:kerwincui * 时间:2021-06-08 * 邮箱:164770707@qq.com * 源码地址:https://gitee.com/kerwincui/wumei-smart * author: kerwincui * create: 2021-06-08 * email:164770707@qq.com * source:https://github.com/kerwincui/wumei-smart ******************************************************************************/ #include "led.h" #include "wifi.h" #include "nvs_storage.h" static TaskHandle_t led_blink_handle = NULL; static ledc_channel_config_t ledc_channel[3]; static eTaskState state=eDeleted; static const char* TAG = "led"; //灯颜色设置,颜色0-255,亮度0-100,fade_time>0则渐变 static void led_rgb_set(uint32_t red,uint32_t green,uint32_t blue, uint32_t brightness,uint32_t fade_time){ uint32_t red_duty=0; uint32_t green_duty=0; uint32_t blue_duty=0; // 13位分辨率值为0-8191,倍数为32.121 if(CATEGORY==2){ red_duty=(uint32_t)(red*32.121*brightness/100); green_duty=(uint32_t)(green*32.121*brightness/100); blue_duty=(uint32_t)(blue*32.121*brightness/100); }else{ red_duty=8191-(red*32.121*brightness/100); green_duty=8191-(green*32.121*brightness/100); blue_duty=8191-(blue*32.121*brightness/100); } if(red_duty>8191) {red_duty=8191;} if(red_duty<0) {red_duty=0;} if(green_duty>8191) {green_duty=8191;} if(green_duty<0) {green_duty=0;} if(blue_duty>8191) {blue_duty=8191;} if(blue_duty<0) {blue_duty=0;} ledc_set_fade_with_time(ledc_channel[0].speed_mode, ledc_channel[0].channel, red_duty, fade_time); ledc_fade_start(ledc_channel[0].speed_mode, ledc_channel[0].channel, LEDC_FADE_NO_WAIT); ledc_set_fade_with_time(ledc_channel[1].speed_mode, ledc_channel[1].channel, green_duty, fade_time); ledc_fade_start(ledc_channel[1].speed_mode, ledc_channel[1].channel, LEDC_FADE_NO_WAIT); ledc_set_fade_with_time(ledc_channel[2].speed_mode, ledc_channel[2].channel, blue_duty, fade_time); ledc_fade_start(ledc_channel[2].speed_mode, ledc_channel[2].channel, LEDC_FADE_NO_WAIT); } //灯闪烁任务 static void led_blink_task(void *arg) { ESP_LOGI(TAG, "led blink"); uint32_t i=0; while(i