void AX_WS2812_Init(void); //WS2812初始化 void AX_WS2812_SetColor(uint8_t (*color)[3], uint8_t len); //WS2812设置灯条颜色 |
/** * @简 述 WS2812设置灯条为单一颜色。 * @参 数 red 红色值 green:绿色值 blue:蓝色值 len:灯个数 * @返回值 无 */ void AX_WS2812_SetOneColor(uint8_t red, uint8_t green, uint8_t blue, uint8_t len) { for(uint8_t i=0; i ws2812_dispbuf[0] = red; ws2812_dispbuf[1] = green; ws2812_dispbuf[2] = blue; } AX_WS2812_SetColor(ws2812_dispbuf, len); } |
int main(void) { uint16_t i=0,j=0; u8 res; //X-CTR100初始化 AX_Init(115200); printf("***X-CTR100 WS2812彩色LED灯例程***rnrn"); //设置系统中断优先级分组2 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //WS2812初始化 AX_WS2812_Init(); //显示黑色(关灯) AX_WS2812_SetOneColor(0,0,0,WS2812_NUM); AX_Delayms(10); while (1) { res = AX_SW_GetSW12Status(); switch (res) { case 0: //8种颜色循环效果 for(j=0; j ws2812_dispbuf[j][0] = COLOR_RGB_LIST[i%8][0]; ws2812_dispbuf[j][1] = COLOR_RGB_LIST[i%8][1]; ws2812_dispbuf[j][2] = COLOR_RGB_LIST[i%8][2]; } AX_WS2812_SetColor(ws2812_dispbuf, WS2812_NUM); AX_Delayms(100); i++; break; case 1: //色环转圈效果 for(j=0; j ws2812_dispbuf[j][0] = COLOR_RGB_LIST[(j+i)%8][0]; ws2812_dispbuf[j][1] = COLOR_RGB_LIST[(j+i)%8][1]; ws2812_dispbuf[j][2] = COLOR_RGB_LIST[(j+i)%8][2]; } AX_WS2812_SetColor(ws2812_dispbuf, WS2812_NUM); AX_Delayms(30); i++; break; case 2: //蓝色呼吸灯效果 for(j=0; j<255; j++) //亮节奏控制 { AX_WS2812_SetOneColor(0,0,j,WS2812_NUM); AX_Delayms(1); } for(j=255; j>0; j--) //灭节奏控制 { AX_WS2812_SetOneColor(0,0,j,WS2812_NUM); AX_Delayms(2); } AX_Delayms(100); break; case 3: //红色单点转圈效果 for(j=0; j ws2812_dispbuf[j][0] = 0; ws2812_dispbuf[j][1] = 0; ws2812_dispbuf[j][2] = 0; } ws2812_dispbuf[i%8][0] = 0xFF; ws2812_dispbuf[i%8][1] = 0x0; ws2812_dispbuf[i%8][2] = 0x0; AX_WS2812_SetColor(ws2812_dispbuf, WS2812_NUM); AX_Delayms(30); i++; break; default: break; } AX_Delayms(10); } } |
更多回帖