呼吸灯效果具有美好的视觉观感,前一段时期感受了一位大佬在MCU中实现呼吸灯颜色渐变效果,很是震撼。这引起了我的兴趣,本文则是实现一种呼吸灯效果(主要在于颜色的渐变体现)。
程序整体视图
程序框图
公式节点程序
int red_is_0 = red == 0 ? 1 : 0;
int green_is_0 = green == 0 ? 1 : 0;
int blue_is_0 = blue == 0 ? 1 : 0;
int color_swicth = (red_is_0 << 2)+ (green_is_0<< 1) + blue_is_0 ;
int huangzhigao = 0;
huangzhigao = (rf<< 2)+ (gf<< 1) + bf ;
switch(huangzhigao)
{
case 1:
blue++;
break;
case 2:
green++;
break;
case 4:
red++;
break;
case 8:
red--;
break;
case 16:
green--;
break;
case 32:
blue--;
break;
}
switch(color_swicth)
{
case 1:
if(255 == green)
{
rf = 2;
gf = 0;
bf = 0;
}
break;
case 2:
if(255 == red)
{
rf = 8;
gf = 0;
bf = 0;
}
break;