for (uint8_t i = 0 ; i < LED_NUM; i++) { led_set(i, g_value_r[i], g_value_g[i], g_value_b[i]); } led_on(); HAL_Delay(100); if (((g_value_r[0] >= 0xFF - g_value_delta) || (g_value_b[0] <= g_value_delta/2) )&& g_value_g[0] == 0x00 && direction == 6) { direction = 1; g_value_r[0] = 0xFF; g_value_g[0] = 0x00; g_value_b[0] = 0x00; } else if (g_value_r[0] == 0xFF && g_value_g[0] >= 0xFF - g_value_delta && g_value_b[0] == 0x00 && direction == 1) { g_value_g[0] = 0xFF; direction = 2; } else if (g_value_r[0] <= g_value_delta && g_value_g[0] == 0xff && g_value_b[0] == 0x00 && direction == 2) { g_value_r[0] = 0x00; direction = 3; } else if (g_value_r[0] == 0x00 && g_value_g[0] == 0xff && g_value_b[0] >= (0xFF - g_value_delta) && direction == 3) { g_value_b[0] = 0xff; direction = 4; } else if (g_value_r[0] == 0x00 && g_value_g[0] <= g_value_delta && g_value_b[0] == 0xff && direction == 4) { g_value_g[0] = 0x00; direction = 5; } else if (g_value_r[0] >= (0x8B - g_value_delta) && g_value_g[0] == 0x00 && g_value_b[0] == 0xff && direction == 5) { direction = 6; g_value_r[0] = 0x8B; g_value_g[0] = 0x00; g_value_b[0] = 0xFF; } if (direction == 1) { g_value_g[0] = g_value_g[0] + g_value_delta; } else if (direction == 2) { g_value_r[0] = g_value_r[0] - g_value_delta; } else if (direction == 3) { g_value_b[0] = g_value_b[0] + g_value_delta; } else if (direction == 4) { g_value_g[0] = g_value_g[0] - g_value_delta; } else if (direction == 5) { g_value_r[0] = g_value_r[0] + g_value_delta; } else if (direction == 6) { g_value_r[0] = g_value_r[0] + g_value_delta/2; g_value_b[0] = g_value_b[0] - g_value_delta; } for (int i = 29 ; i >0; i-- ) { g_value_r[i] = g_value_r[i-1]; g_value_g[i] = g_value_g[i-1]; g_value_b[i] = g_value_b[i-1]; }
时间: 2024-03-07 19:51:42 浏览: 164
( ap6181_sina33m_sc3817r验证通过_20170710_1608没有外层目录.7z
这段代码是用于控制WS2812 RGB LED的颜色变化的。首先使用led_set()函数设置所有LED的颜色为g_value_r、g_value_g、g_value_b数组中的值,然后使用led_on()函数启动定时器PWM输出数据。接着使用HAL_Delay()函数延时100ms,然后根据g_value_r、g_value_g、g_value_b数组中第0个元素的值以及direction变量的值来决定LED的颜色变化方向和颜色值。direction变量的值代表LED颜色变化的6个方向,分别为1~6。根据direction的值来决定修改哪个颜色的值,以及修改的方向。最后使用for循环将g_value_r、g_value_g、g_value_b数组中的值向后移动一位,以实现LED颜色的流动效果。
阅读全文