添加支持多个RGB灯显示
This commit is contained in:
@@ -6,22 +6,24 @@ rmt_transmit_config_t tx_config = {
|
|||||||
.loop_count = 0, // no transfer loop
|
.loop_count = 0, // no transfer loop
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static rgb_color_t expression[EXAMPLE_LED_NUMBERS];
|
||||||
|
static rgb_color_t expression_lat[EXAMPLE_LED_NUMBERS] = {0};
|
||||||
|
static uint16_t rgb_toggle_cnt[EXAMPLE_LED_NUMBERS] = {10,10};
|
||||||
|
static uint16_t rgb_toggle_cnt_lat[EXAMPLE_LED_NUMBERS] = {0};
|
||||||
|
|
||||||
static uint8_t led_strip_pixels[EXAMPLE_LED_NUMBERS * 3];
|
static uint8_t led_strip_pixels[EXAMPLE_LED_NUMBERS * 3];
|
||||||
uint16_t toggle_cycle = 1000;
|
uint16_t toggle_cycle = 1000;
|
||||||
bool toggle_flag = true;
|
bool toggle_flag[EXAMPLE_LED_NUMBERS] = {true,true};
|
||||||
static uint8_t rgb_color_index = RGB_COLOR_RAD;
|
|
||||||
|
|
||||||
static uint8_t color_lat = 0, cyle_lat = 0;
|
rgb_color_t rgb_color_rad = {0,255,0,0,0,1,0,RGB_COLOR_RAD};
|
||||||
|
rgb_color_t rgb_color_orange = {0,255,80,0,0,1,0,RGB_COLOR_ORANGE};
|
||||||
rgb_color_t rgb_color_rad = {0,255,0,0,0,1,0};
|
rgb_color_t rgb_color_green = {0,0,255,0,0,1,0,RGB_COLOR_GREEN};
|
||||||
rgb_color_t rgb_color_orange = {0,255,80,0,0,1,0};
|
rgb_color_t rgb_color_blue = {0,0,0,255,0,1,0,RGB_COLOR_BLUE};
|
||||||
rgb_color_t rgb_color_green = {0,0,255,0,0,1,0};
|
rgb_color_t rgb_color_cyan = {0,0,255,255,0,1,0,RGB_COLOR_CYAN};
|
||||||
rgb_color_t rgb_color_blue = {0,0,0,255,0,1,0};
|
rgb_color_t rgb_color_purple = {0,255,0,255,0,1,0,RGB_COLOR_PURPLE};
|
||||||
rgb_color_t rgb_color_cyan = {0,0,255,255,0,1,0};
|
rgb_color_t rgb_color_white = {0,255,255,255,0,1,0,RGB_COLOR_WHITE};
|
||||||
rgb_color_t rgb_color_purple = {0,255,0,255,0,1,0};
|
rgb_color_t rgb_color_green_white = {0,0,255,0,0,2,20,RGB_COLOR_GREEN_WHITE};
|
||||||
rgb_color_t rgb_color_white = {0,255,255,255,0,1,0};
|
rgb_color_t rgb_color_green_purple = {0,0,255,0,0,2,20,RGB_COLOR_GREEN_PURPLE};
|
||||||
rgb_color_t rgb_color_green_white = {0,0,255,0,0,2,5};
|
|
||||||
rgb_color_t rgb_color_green_purple = {0,0,255,0,0,2,5};
|
|
||||||
void led_strip_init(void)
|
void led_strip_init(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -48,7 +50,8 @@ void led_strip_init(void)
|
|||||||
|
|
||||||
// ESP_LOGI(TAG, "Start LED rainbow chase");
|
// ESP_LOGI(TAG, "Start LED rainbow chase");
|
||||||
|
|
||||||
|
rgb_color_change(0,RGB_COLOR_ORANGE);
|
||||||
|
rgb_color_change(1,RGB_COLOR_ORANGE);
|
||||||
}
|
}
|
||||||
void led_strip_set_pixel(uint8_t pin, uint8_t index, uint8_t green, uint8_t blue, uint8_t red)
|
void led_strip_set_pixel(uint8_t pin, uint8_t index, uint8_t green, uint8_t blue, uint8_t red)
|
||||||
{
|
{
|
||||||
@@ -71,74 +74,97 @@ void work_rgb_led_start(void)
|
|||||||
|
|
||||||
void _work_rgb_led(void *arg)
|
void _work_rgb_led(void *arg)
|
||||||
{
|
{
|
||||||
static rgb_color_t* expression;
|
static uint16_t rgb_toggle_cnt_update[EXAMPLE_LED_NUMBERS] = {10,10};
|
||||||
static uint8_t rgb_color_index_lat = 255;
|
if(!rgb_toggle_cnt_update[0]--)
|
||||||
if(rgb_color_index_lat != rgb_color_index)
|
|
||||||
{
|
{
|
||||||
rgb_color_index_lat = rgb_color_index;
|
rgb_toggle_cnt_update[0] = rgb_toggle_cnt[0];
|
||||||
switch (rgb_color_index)
|
rgb_toggle(0,&expression[0]);
|
||||||
{
|
|
||||||
case RGB_COLOR_RAD:
|
|
||||||
expression = &rgb_color_rad;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_ORANGE:
|
|
||||||
expression = &rgb_color_orange;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_GREEN:
|
|
||||||
expression = &rgb_color_green;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_WHITE:
|
|
||||||
expression = &rgb_color_white;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_PURPLE:
|
|
||||||
expression = &rgb_color_purple;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_CYAN:
|
|
||||||
expression = &rgb_color_cyan;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_BLUE:
|
|
||||||
expression = &rgb_color_blue;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_GREEN_WHITE:
|
|
||||||
expression = &rgb_color_green_white;
|
|
||||||
break;
|
|
||||||
case RGB_COLOR_GREEN_PURPLE:
|
|
||||||
expression = &rgb_color_green_purple;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(!rgb_toggle_cnt_update[1]--)
|
||||||
|
{
|
||||||
|
rgb_toggle_cnt_update[1] = rgb_toggle_cnt[1];
|
||||||
|
rgb_toggle(1,&expression[1]);
|
||||||
|
}
|
||||||
|
os_work_later(WORD_TIME_MS);
|
||||||
|
}
|
||||||
|
void rgb_update_cyle(uint8_t index, uint16_t cyle)
|
||||||
|
{
|
||||||
|
toggle_flag[index] = (cyle == 888 ? false : true);
|
||||||
|
|
||||||
rgb_toggle(expression);
|
rgb_toggle_cnt[index] = cyle / WORD_TIME_MS - 1;
|
||||||
os_work_later(toggle_cycle * 0.5);
|
}
|
||||||
|
void rgb_color_change(uint8_t index, uint8_t color)
|
||||||
|
{
|
||||||
|
switch(color)
|
||||||
|
{
|
||||||
|
case RGB_COLOR_RAD:
|
||||||
|
memcpy(&expression[index], &rgb_color_rad, sizeof(rgb_color_rad));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_ORANGE:
|
||||||
|
memcpy(&expression[index], &rgb_color_orange, sizeof(rgb_color_orange));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_GREEN:
|
||||||
|
memcpy(&expression[index], &rgb_color_green, sizeof(rgb_color_green));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_WHITE:
|
||||||
|
memcpy(&expression[index], &rgb_color_white, sizeof(rgb_color_white));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_PURPLE:
|
||||||
|
memcpy(&expression[index], &rgb_color_purple, sizeof(rgb_color_purple));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_CYAN:
|
||||||
|
memcpy(&expression[index], &rgb_color_cyan, sizeof(rgb_color_cyan));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_BLUE:
|
||||||
|
memcpy(&expression[index], &rgb_color_blue, sizeof(rgb_color_blue));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_GREEN_WHITE:
|
||||||
|
memcpy(&expression[index], &rgb_color_green_white, sizeof(rgb_color_green_white));
|
||||||
|
break;
|
||||||
|
case RGB_COLOR_GREEN_PURPLE:
|
||||||
|
memcpy(&expression[index], &rgb_color_green_purple, sizeof(rgb_color_green_purple));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
expression[index].index = index;
|
||||||
|
}
|
||||||
|
void rgb_toggle(uint8_t index, rgb_color_t* rgb_color)
|
||||||
|
{
|
||||||
|
if(rgb_color->color_cnt > 1)
|
||||||
|
{
|
||||||
|
breathing_color_change(index,rgb_color);
|
||||||
|
led_strip_set_pixel(0,rgb_color->index,rgb_color->green,rgb_color->blue,rgb_color->red);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(rgb_color->toggle_flag == 0)
|
||||||
|
led_strip_set_pixel(0,rgb_color->index,rgb_color->green,rgb_color->blue,rgb_color->red);
|
||||||
|
else
|
||||||
|
led_strip_set_pixel(0,rgb_color->index,0,0,0);
|
||||||
|
|
||||||
|
if(toggle_flag[index] == true)
|
||||||
|
rgb_color->toggle_flag = !rgb_color->toggle_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rgb_update_cyle(uint16_t cyle)
|
uint8_t breathing_dispose(uint8_t index, rgb_color_t* rgb_color,int16_t* vel, uint8_t color_min, uint8_t color_max)
|
||||||
{
|
{
|
||||||
toggle_flag = (cyle == 888 ? false : true);
|
static int dir[EXAMPLE_LED_NUMBERS] = {1,1}, color_dir[EXAMPLE_LED_NUMBERS] = {1,1}, color_cnt[EXAMPLE_LED_NUMBERS] = {0,0};
|
||||||
|
*vel += dir[index] * rgb_color->colortoggle_speed;
|
||||||
|
if(*vel > color_max){*vel = color_max; dir[index] = -1;}
|
||||||
|
else if(*vel < color_min){*vel = color_min; dir[index] = 1; color_cnt[index] += color_dir[index];}
|
||||||
|
|
||||||
toggle_cycle = cyle;
|
if(color_cnt[index] >= rgb_color->color_cnt -1 )
|
||||||
|
color_dir[index] = -1;
|
||||||
|
else if(color_cnt[index] <= 0)
|
||||||
|
color_dir[index] = 1;
|
||||||
|
|
||||||
|
return color_cnt[index];
|
||||||
}
|
}
|
||||||
uint8_t breathing_dispose(rgb_color_t* rgb_color,int16_t* vel, uint8_t color_min, uint8_t color_max)
|
void breathing_color_change(uint8_t index, rgb_color_t* rgb_color)
|
||||||
{
|
{
|
||||||
static int dir = 1, color_dir = 1, color_cnt = 0;
|
static int16_t COLOR_SUM[EXAMPLE_LED_NUMBERS];
|
||||||
*vel += dir * rgb_color->colortoggle_speed;
|
uint8_t color_cnt = breathing_dispose(index, rgb_color, &COLOR_SUM[index], 0, 255);
|
||||||
if(*vel > color_max){*vel = color_max; dir = -1;}
|
switch (rgb_color->color_type)
|
||||||
else if(*vel < color_min){*vel = color_min; dir = 1; color_cnt += color_dir;}
|
|
||||||
|
|
||||||
if(color_cnt >= rgb_color->color_cnt -1 )
|
|
||||||
color_dir = -1;
|
|
||||||
else if(color_cnt <= 0)
|
|
||||||
color_dir = 1;
|
|
||||||
|
|
||||||
return color_cnt;
|
|
||||||
}
|
|
||||||
void breathing_color_change(rgb_color_t* rgb_color)
|
|
||||||
{
|
|
||||||
static int16_t COLOR_SUM;
|
|
||||||
uint8_t color_cnt = breathing_dispose(rgb_color, &COLOR_SUM, 0, 255);
|
|
||||||
switch (rgb_color_index)
|
|
||||||
{
|
{
|
||||||
case RGB_COLOR_GREEN_WHITE:
|
case RGB_COLOR_GREEN_WHITE:
|
||||||
{
|
{
|
||||||
@@ -147,15 +173,15 @@ void breathing_color_change(rgb_color_t* rgb_color)
|
|||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
rgb_color->red = 0;
|
rgb_color->red = 0;
|
||||||
rgb_color->green = (uint8_t)COLOR_SUM;
|
rgb_color->green = (uint8_t)COLOR_SUM[index];
|
||||||
rgb_color->blue = 0;
|
rgb_color->blue = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
rgb_color->red = (uint8_t)COLOR_SUM;
|
rgb_color->red = (uint8_t)COLOR_SUM[index];
|
||||||
rgb_color->green = (uint8_t)COLOR_SUM;
|
rgb_color->green = (uint8_t)COLOR_SUM[index];
|
||||||
rgb_color->blue = (uint8_t)COLOR_SUM;
|
rgb_color->blue = (uint8_t)COLOR_SUM[index];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,65 +194,45 @@ void breathing_color_change(rgb_color_t* rgb_color)
|
|||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
rgb_color->red = 0;
|
rgb_color->red = 0;
|
||||||
rgb_color->green = (uint8_t)COLOR_SUM;
|
rgb_color->green = (uint8_t)COLOR_SUM[index];
|
||||||
rgb_color->blue = 0;
|
rgb_color->blue = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
rgb_color->red = (uint8_t)COLOR_SUM;
|
rgb_color->red = (uint8_t)COLOR_SUM[index];
|
||||||
rgb_color->green = 0;
|
rgb_color->green = 0;
|
||||||
rgb_color->blue = (uint8_t)COLOR_SUM;
|
rgb_color->blue = (uint8_t)COLOR_SUM[index];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void rgb_toggle(rgb_color_t* rgb_color)
|
|
||||||
{
|
|
||||||
if(rgb_color->color_cnt > 1)
|
|
||||||
{
|
|
||||||
breathing_color_change(rgb_color);
|
|
||||||
led_strip_set_pixel(0,rgb_color->index,rgb_color->green,rgb_color->blue,rgb_color->red);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(rgb_color->toggle_flag == 0)
|
|
||||||
led_strip_set_pixel(0,rgb_color->index,rgb_color->green,rgb_color->blue,rgb_color->red);
|
|
||||||
else
|
|
||||||
led_strip_set_pixel(0,rgb_color->index,0,0,0);
|
|
||||||
|
|
||||||
if(toggle_flag == true)
|
|
||||||
rgb_color->toggle_flag = !rgb_color->toggle_flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rgb_color_change(uint8_t index, uint8_t color)
|
|
||||||
{
|
|
||||||
rgb_color_index = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rgb_Indicator_light_on(uint8_t index, uint8_t color, uint16_t cyle)
|
void rgb_Indicator_light_on(uint8_t index, uint8_t color, uint16_t cyle)
|
||||||
{
|
{
|
||||||
if(color_lat != rgb_color_index && rgb_color_index != color)
|
if(expression_lat[index].color_type == 0 && expression_lat[index].color_type != color)
|
||||||
{
|
{
|
||||||
color_lat = rgb_color_index;
|
memcpy(&expression_lat[index], &expression[index], sizeof(rgb_color_t));
|
||||||
rgb_color_change(index, color);
|
rgb_color_change(index, color);
|
||||||
}
|
}
|
||||||
if(cyle_lat != cyle && toggle_cycle != cyle)
|
if(rgb_toggle_cnt_lat[index] == 0 && rgb_toggle_cnt[index] != cyle)
|
||||||
{
|
{
|
||||||
cyle_lat = toggle_cycle;
|
rgb_toggle_cnt_lat[index] = rgb_toggle_cnt[index];
|
||||||
rgb_update_cyle(cyle);
|
rgb_update_cyle(index, cyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
void rgb_Indicator_light_off(uint8_t index)
|
void rgb_Indicator_light_off(uint8_t index)
|
||||||
{
|
{
|
||||||
rgb_color_change(index, color_lat);
|
|
||||||
rgb_update_cyle(cyle_lat);
|
rgb_color_change(index, expression_lat[index].color_type);
|
||||||
color_lat = 0;
|
rgb_update_cyle(index,(rgb_toggle_cnt_lat[index] + 1) * WORD_TIME_MS );
|
||||||
cyle_lat = 0;
|
|
||||||
|
memset(&expression_lat[index], 0, sizeof(rgb_color_t));
|
||||||
|
rgb_toggle_cnt_lat[index] = 0;
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "led_strip_encoder.h"
|
#include "led_strip_encoder.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "driver/rmt_tx.h"
|
#include "driver/rmt_tx.h"
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
#define EXAMPLE_LED_NUMBERS 2
|
#define EXAMPLE_LED_NUMBERS 2
|
||||||
#define EXAMPLE_CHASE_SPEED_MS 10
|
#define EXAMPLE_CHASE_SPEED_MS 10
|
||||||
|
|
||||||
|
#define WORD_TIME_MS 50
|
||||||
// static const char *TAG = "example";
|
// static const char *TAG = "example";
|
||||||
|
|
||||||
extern rmt_channel_handle_t led_chan;
|
extern rmt_channel_handle_t led_chan;
|
||||||
@@ -32,7 +34,7 @@ typedef struct rgb_color_s
|
|||||||
uint8_t toggle_flag;
|
uint8_t toggle_flag;
|
||||||
uint8_t color_cnt;
|
uint8_t color_cnt;
|
||||||
uint8_t colortoggle_speed;
|
uint8_t colortoggle_speed;
|
||||||
|
uint8_t color_type;
|
||||||
}rgb_color_t;
|
}rgb_color_t;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
@@ -53,8 +55,10 @@ void led_strip_init(void);
|
|||||||
void led_strip_set_pixel(uint8_t pin, uint8_t index, uint8_t green, uint8_t blue, uint8_t red);
|
void led_strip_set_pixel(uint8_t pin, uint8_t index, uint8_t green, uint8_t blue, uint8_t red);
|
||||||
void work_rgb_led_start(void);
|
void work_rgb_led_start(void);
|
||||||
void _work_rgb_led(void *arg);
|
void _work_rgb_led(void *arg);
|
||||||
void rgb_update_cyle(uint16_t cyle);
|
void rgb_update_cyle(uint8_t index, uint16_t cyle);
|
||||||
void rgb_toggle(rgb_color_t* rgb_color);
|
void rgb_toggle(uint8_t index, rgb_color_t* rgb_color);
|
||||||
void rgb_color_change(uint8_t index, uint8_t color);
|
void rgb_color_change(uint8_t index, uint8_t color);
|
||||||
void rgb_Indicator_light_on(uint8_t index, uint8_t color, uint16_t cyle);
|
void rgb_Indicator_light_on(uint8_t index, uint8_t color, uint16_t cyle);
|
||||||
void rgb_Indicator_light_off(uint8_t index);
|
void rgb_Indicator_light_off(uint8_t index);
|
||||||
|
|
||||||
|
void breathing_color_change(uint8_t index, rgb_color_t* rgb_color);
|
||||||
Reference in New Issue
Block a user