扩展十三种灯光效果模式

This commit is contained in:
2026-07-28 13:14:11 +08:00
parent 6532524f81
commit e66570c005
7 changed files with 185 additions and 229 deletions
+167 -223
View File
@@ -66,88 +66,52 @@ void set_mode(){
if(choose_mode_bh==0){
choose_mode_bh=1;
switch(choose_mode_falsg){
//
case 0:
//暖光
W_PWM=Color_table_static[0][0];
C_PWM=Color_table_static[0][1];
driveMode=1;//切换为暖光的底层输出
Mode=mode0;
W_PWM=100U; C_PWM=0U; driveMode=1U; Mode=mode0;
break;
case 1:
//冷光
W_PWM=Color_table_static[2][0];
C_PWM=Color_table_static[2][1];
driveMode=2;//切换为冷光的底层输出
Mode=mode0;
W_PWM=0U; C_PWM=100U; driveMode=2U; Mode=mode0;
break;
case 2:
//中性光
W_PWM=Color_table_static[1][0];
C_PWM=Color_table_static[1][1];
driveMode=0;//切换为中性光的底层输出
Mode=mode0;
W_PWM=50U; C_PWM=50U; driveMode=0U; Mode=mode0;
break;
case 3:
//暖光呼吸
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode1;
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode1;
break;
case 4:
//冷光呼吸
W_PWM=Color_table[2][0];
C_PWM=Color_table[2][1];
driveMode=2;//切换为中性光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode1;
case 4:
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=1U; Mode=mode1;
break;
case 5:
//三个色温轮询呼吸//先从暖光开始呼吸
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode1;
case 5:
W_PWM=68U; C_PWM=68U; driveMode=0U; direction=1U; Mode=mode1;
break;
case 6:
//暖光跳变
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode2;
case 6:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode1;
break;
case 7:
//中性光跳变
W_PWM=Color_table[1][0];
C_PWM=Color_table[1][1];
driveMode=0;//切换为中性光的底层输出
Mode=mode2;
case 7:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode3;
break;
case 8:
//冷光跳变
W_PWM=Color_table[2][0];
C_PWM=Color_table[2][1];
driveMode=2;//切换为中性光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode2;
case 8:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=1U; Mode=mode2;
break;
case 9:
//暖光中性光冷交替跳变,先从暖光跳变
W_PWM=Color_table[0][0];
C_PWM=Color_table[0][1];
driveMode=1;//切换为暖光的底层输出
direction=1;//呼吸方向恢复默认值
Mode=mode2;
case 9:
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=1U; Mode=mode2;
break;
case 10:
W_PWM=50U; C_PWM=50U; driveMode=0U; direction=1U; Mode=mode2;
break;
case 11:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U; Mode=mode2;
break;
case 12:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U; Mode=mode2;
break;
case CUSTOM_TEMPERATURE_MODE:
Mode=mode0;
break;
default:
choose_mode_falsg=0U;
W_PWM=100U; C_PWM=0U; driveMode=1U; Mode=mode0;
break;
case 10://圆环模式
Mode=mode0;
break;
}
if(mode_entry_initialized)
{
@@ -214,112 +178,85 @@ static void breathe_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag) {
// }
}
}
void Mode1(){ //呼吸
if(choose_mode_falsg==3){ //暖光呼吸
breathe_fun(&C_PWM,&W_PWM,0);
}else if(choose_mode_falsg==4){//冷光呼吸
breathe_fun(&W_PWM,&C_PWM,0);
}else if(choose_mode_falsg==5){
switch (direction) {
case 0:
breathespeed_flag=0;
W_PWM += 1;
C_PWM = 0;
if (W_PWM >= 100) {
direction = 1;
}
break;
case 1:
breathespeed_flag=0;
W_PWM -= 1;
C_PWM = 0;
if (W_PWM <= 1) {
direction = THREE_COLOR_WAIT_NEUTRAL;
W_PWM = 0;
C_PWM = 0;
}
break;
case 2:
breathespeed_flag=1;
W_PWM += 1;
C_PWM += 1;
if (W_PWM >= 68) {
W_PWM=68;
C_PWM=68;
direction = 3;
}
break;
case 3:
breathespeed_flag=1;
W_PWM -= 1;
C_PWM -= 1;
if (W_PWM <=1) {
direction = THREE_COLOR_WAIT_COLD;
W_PWM = 0;
C_PWM = 0;
}
break;
case 4:
breathespeed_flag=0;
W_PWM = 0;
C_PWM += 1;
if (C_PWM >= 100) {
direction = 5;
}
break;
case 5:
breathespeed_flag=0;
W_PWM = 0;
C_PWM -= 1;
if (C_PWM <=1){
direction = THREE_COLOR_WAIT_WARM;
W_PWM = 0;
C_PWM = 0;
}
break;
case THREE_COLOR_WAIT_NEUTRAL:
breathespeed_flag=1;
W_PWM = 0;
C_PWM = 0;
if(W_PWM_duty == 0U && C_PWM_duty == 0U){
driveMode=0;
W_PWM = 1;
C_PWM = 1;
direction = 2;
}
break;
case THREE_COLOR_WAIT_COLD:
breathespeed_flag=0;
W_PWM = 0;
C_PWM = 0;
if(W_PWM_duty == 0U && C_PWM_duty == 0U){
driveMode=2;
C_PWM = 1;
direction = 4;
}
break;
case THREE_COLOR_WAIT_WARM:
breathespeed_flag=0;
W_PWM = 0;
C_PWM = 0;
if(W_PWM_duty == 0U && C_PWM_duty == 0U){
driveMode=1;
W_PWM = 1;
direction = 0;
}
break;
}
static void neutral_breathe_fun(void)
{
breathespeed_flag=1U;
if(direction==1U){
if(W_PWM>1U){ W_PWM--; C_PWM--; }
if(W_PWM<=1U){ W_PWM=1U; C_PWM=1U; direction=0U; }
}else{
if(W_PWM<68U){ W_PWM++; C_PWM++; }
if(W_PWM>=68U){ W_PWM=68U; C_PWM=68U; direction=1U; }
}
//(void)0;/* transition */
(void)0;/* transition */
}
void Mode1(void)
{
if(choose_mode_falsg==3U){
breathespeed_flag=0U;
breathe_fun(&C_PWM,&W_PWM,0U);
}else if(choose_mode_falsg==4U){
breathespeed_flag=0U;
breathe_fun(&W_PWM,&C_PWM,0U);
}else if(choose_mode_falsg==5U){
neutral_breathe_fun();
}else if(choose_mode_falsg==6U){
switch(direction){
case 0U:
breathespeed_flag=0U;
W_PWM++; C_PWM=0U;
if(W_PWM>=100U){ W_PWM=100U; direction=1U; }
break;
case 1U:
breathespeed_flag=0U;
if(W_PWM>0U) W_PWM--;
C_PWM=0U;
if(W_PWM<=1U){ W_PWM=0U; direction=THREE_COLOR_WAIT_COLD; }
break;
case 4U:
breathespeed_flag=0U;
W_PWM=0U; C_PWM++;
if(C_PWM>=100U){ C_PWM=100U; direction=5U; }
break;
case 5U:
breathespeed_flag=0U;
W_PWM=0U;
if(C_PWM>0U) C_PWM--;
if(C_PWM<=1U){ C_PWM=0U; direction=THREE_COLOR_WAIT_NEUTRAL; }
break;
case 2U:
breathespeed_flag=1U;
W_PWM++; C_PWM++;
if(W_PWM>=68U){ W_PWM=68U; C_PWM=68U; direction=3U; }
break;
case 3U:
breathespeed_flag=1U;
if(W_PWM>0U) W_PWM--;
if(C_PWM>0U) C_PWM--;
if(W_PWM<=1U){ W_PWM=0U; C_PWM=0U; direction=THREE_COLOR_WAIT_WARM; }
break;
case THREE_COLOR_WAIT_COLD:
breathespeed_flag=0U; W_PWM=0U; C_PWM=0U;
if(W_PWM_duty==0U && C_PWM_duty==0U){
driveMode=2U; C_PWM=1U; direction=4U;
}
break;
case THREE_COLOR_WAIT_NEUTRAL:
breathespeed_flag=1U; W_PWM=0U; C_PWM=0U;
if(W_PWM_duty==0U && C_PWM_duty==0U){
driveMode=0U; W_PWM=1U; C_PWM=1U; direction=2U;
}
break;
case THREE_COLOR_WAIT_WARM:
default:
breathespeed_flag=0U; W_PWM=0U; C_PWM=0U;
if(W_PWM_duty==0U && C_PWM_duty==0U){
driveMode=1U; W_PWM=1U; direction=0U;
}
break;
}
}
}
void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
if(flag==0){
*PWM_1 = 0;
@@ -332,8 +269,8 @@ void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
}
}else if(flag==1){
if (!direction){
*PWM_1 = 40;
*PWM_2 = 40;
*PWM_1 = 50;
*PWM_2 = 50;
direction = 1;
} else {
*PWM_1 = 0;
@@ -343,58 +280,65 @@ void jump_fun(uint16_t *PWM_1, uint16_t *PWM_2, uint8_t flag){
}
}
void Mode2(){ //跳变
//printf("dd=%d--%d\r\n",W_PWM,W_PWM);
if(choose_mode_falsg==6){
jump_fun(&C_PWM,&W_PWM,0); //暖光跳变
}else if(choose_mode_falsg==7){
jump_fun(&W_PWM,&C_PWM,1); //中光跳变
}else if(choose_mode_falsg==8){
jump_fun(&W_PWM,&C_PWM,0); //冷光跳变
}else if(choose_mode_falsg==9){
switch (direction) {
case 1:
W_PWM =100;
C_PWM = 0;
direction = 2;
break;
case 2:
W_PWM = 0;
C_PWM = 0;
direction = 3;
driveMode=0;
break;
case 3:
W_PWM =40;
C_PWM =40;
direction = 4;
break;
case 4:
W_PWM =0;
C_PWM =0;
direction = 5;
driveMode=2;
break;
case 5:
W_PWM = 0;
C_PWM = 100;
direction = 6;
break;
case 6:
W_PWM = 0;
C_PWM = 0;
direction = 1;
driveMode=1;
break;
}
void Mode2(void)
{
if(choose_mode_falsg==8U){
jump_fun(&C_PWM,&W_PWM,0U);
}else if(choose_mode_falsg==9U){
jump_fun(&W_PWM,&C_PWM,0U);
}else if(choose_mode_falsg==10U){
jump_fun(&W_PWM,&C_PWM,1U);
}else if(choose_mode_falsg==11U){
switch(direction){
case 1U:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U;
break;
case 2U:
W_PWM=0U; C_PWM=100U; driveMode=2U; direction=3U;
break;
default:
W_PWM=50U; C_PWM=50U; driveMode=0U; direction=1U;
break;
}
(void)0;/* transition */
}else if(choose_mode_falsg==12U){
switch(direction){
case 1U:
W_PWM=100U; C_PWM=0U; driveMode=1U; direction=2U;
break;
case 2U:
W_PWM=0U; C_PWM=0U; driveMode=2U; direction=3U;
break;
case 3U:
W_PWM=0U; C_PWM=100U; direction=4U;
break;
case 4U:
W_PWM=0U; C_PWM=0U; driveMode=0U; direction=5U;
break;
case 5U:
W_PWM=50U; C_PWM=50U; direction=6U;
break;
default:
W_PWM=0U; C_PWM=0U; driveMode=1U; direction=1U;
break;
}
}
}
void Mode3(){ //爆闪 //无
(void)0;/* transition */
void Mode3(void)
{
if(choose_mode_falsg!=7U) return;
if(direction==1U){
if(C_PWM<100U) C_PWM++;
W_PWM=100U-C_PWM;
if(C_PWM>=100U){ C_PWM=100U; W_PWM=0U; direction=0U; }
}else{
if(C_PWM>0U) C_PWM--;
W_PWM=100U-C_PWM;
if(C_PWM==0U){ W_PWM=100U; direction=1U; }
}
if(C_PWM==0U) driveMode=1U;
else if(W_PWM==0U) driveMode=2U;
else driveMode=0U;
}
pfunc modefunctin[] = { //模式切换,一共15个模式
Mode0,
@@ -417,7 +361,7 @@ void choice_mode(){
}else if(Mode==mode2){
startTimer(&timer1,time_2[Speed]);
}else if(Mode==mode3){
startTimer(&timer1,time_3[Speed]);//
startTimer(&timer1,time_1[Speed]);//
}
modefunctin[Mode]();