|
- /****************************************************************************************
- * WS2811 彩燈驅(qū)動(dòng)函數(shù)
- *
- * 調(diào)用方法:
- * 修改宏定義: #define nWs 1 // 有多少顆WS2811級(jí)聯(lián)
- * WS_Init(); // IO初始化
- * WsDat[0] = 0x808080;//顯存賦值
- * WS_SetAll(); // 發(fā)送數(shù)據(jù)
- * ColorToColor(unsigned long color0, unsigned long color1);// 顏色漸變算法
- *
- * 作者:星希望(已校驗(yàn))
- * 日期:2015年6月24日
- ****************************************************************************************/
- #include "includes.h"
- #define RCC_PAout RCC_AHBPeriph_GPIOB
- #define PORT_PAout GPIOB
- #define PIN_PAout GPIO_Pin_15
- #define RCC_PEN RCC_AHBPeriph_GPIOB
- #define PORT_PEN GPIOB
- #define PIN_PEN GPIO_Pin_9
- #define PAout_0() PORT_PAout->BRR = PIN_PAout
- #define PAout_1() PORT_PAout->BSRR = PIN_PAout
- #define PEN_0() PORT_PEN->BRR = PIN_PEN
- #define PEN_1() PORT_PEN->BSRR = PIN_PEN
- /* 顯存 */
- unsigned long WsDat[nWs];
- uint32_t WsCol[nWs];
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WS_Init
- * 功能說(shuō)明: 初始化WS2811輸出GPIO
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WS_Init()
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- //端口時(shí)鐘,使能
- RCC_AHBPeriphClockCmd(RCC_PAout | RCC_PEN, ENABLE);
- // 端口配置
- GPIO_InitStruct.GPIO_Pin = PIN_PAout; // PIN
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; // 推挽輸出
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // IO口速度為50MHz
- GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
- GPIO_Init(PORT_PAout, &GPIO_InitStruct); // 根據(jù)設(shè)定參數(shù)初始化
- GPIO_InitStruct.GPIO_Pin = PIN_PEN; // PIN
- GPIO_Init(PORT_PEN, &GPIO_InitStruct); // 根據(jù)設(shè)定參數(shù)初始化
- PEN_1();
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: delay2us
- * 功能說(shuō)明: 延時(shí)2us
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void delay2us(void)
- {
- unsigned char i;
- for(i=0; i<12; i++);
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: delay05us
- * 功能說(shuō)明: 延時(shí)0.5us
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void delay05us(void)
- {
- unsigned char i;
- for(i=0; i<2; i++);
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TX0,TX1
- * 功能說(shuō)明: 高速模式(最快)發(fā)送碼值0 ,1
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void TX0() { PAout_1(); delay05us; PAout_0(); delay_us(2); } // 發(fā)送0
- void TX1() { PAout_1(); delay_us(2); PAout_0(); delay05us; } // 發(fā)送1
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: TXL0,TXL1
- * 功能說(shuō)明: 速度降一倍發(fā)送碼值0 ,1
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void TXL0(void) { PAout_1(); delay2us; PAout_0(); delay_us(5); } // 發(fā)送0
- void TXL1(void) { PAout_1(); delay_us(5); PAout_0(); delay2us; } // 發(fā)送1
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WS_Reset
- * 功能說(shuō)明: 發(fā)送碼值 幀單位
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */void WS_Reset() {PAout_0() ; delay_us(60); PAout_1();}//PAout_0();
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WS_Set1
- * 功能說(shuō)明: 高速發(fā)送24Bit數(shù)據(jù)
- * 形 參:dat,發(fā)送的數(shù)據(jù)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WS_SetH(unsigned long dat)
- {
- unsigned char i;
- for(i=0; i<24; i++)
- {
- if(0x800000 == (dat & 0x800000) ) TX1();
- else TX0();
- dat<<=1; //左移一位
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WS_SetL
- * 功能說(shuō)明: 低速發(fā)送24Bit數(shù)據(jù)
- * 形 參:dat,發(fā)送的數(shù)據(jù)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WS_SetL(unsigned long dat)
- {
- unsigned char i;
- for(i=0; i<24; i++)
- {
- if(0x800000 == (dat & 0x800000) ) TXL1();
- else TXL0();
- dat<<=1; //左移一位
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WS_SetAll
- * 功能說(shuō)明: 發(fā)送數(shù)組內(nèi)全部數(shù)據(jù)
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WS_L_SetAll()
- {
- unsigned char j;
- for (j=0; j<20; j++)
- {
- //WsCol[j] = SpiData.SpiData[j * 3]<<16 | SpiData.SpiData[j * 3 + 1]<<8 | SpiData.SpiData[j * 3 + 2];
- WsCol[j] = WsDat[j];
- WS_SetH(WsCol[j]); // j 級(jí)聯(lián)個(gè)數(shù)/ 0
- }
- WS_Reset();
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WS_SetAll
- * 功能說(shuō)明: 發(fā)送數(shù)組內(nèi)全部數(shù)據(jù)
- * 形 參:無(wú)
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WS_H_SetAll()
- {
- unsigned char j;
- for (j=0; j<nWs; j++)
- {
- //WsCol[j] = SpiData.SpiData[j * 3]<<16 | SpiData.SpiData[j * 3 + 1]<<8 | SpiData.SpiData[j * 3 + 2];
- WsCol[j] = WsDat[j];
- WS_SetH(WsCol[j]); // j 級(jí)聯(lián)個(gè)數(shù)/ 0
- }
- WS_Reset();
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: abs0
- * 功能說(shuō)明: 求絕對(duì)值
- * 形 參:num,比較后的數(shù)據(jù)
- * 返 回 值: num,形參的絕對(duì)值
- *********************************************************************************************************
- */
- unsigned char abs0(int num)
- {
- if (num>0) return num;
- num = -num;
- return (unsigned char) num;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: ColorToColor
- * 功能說(shuō)明: 顏色漸變算法(正向)
- * 形 參:color0、color1 從一種顏色變到別一種顏色
- * 返 回 值: color 變化后的顏色
- *********************************************************************************************************
- */
- void ColorToColor(unsigned long color0, unsigned long color1)
- {
- unsigned char Red0, Green0, Blue0; // 起始三原色
- unsigned char Red1, Green1, Blue1; // 結(jié)果三原色
- int RedMinus, GreenMinus, BlueMinus; // 顏色差(color1 - color0)
- unsigned char NStep; // 需要幾步
- float RedStep, GreenStep, BlueStep; // 各色步進(jìn)值
- unsigned long color; // 結(jié)果色
- unsigned char i;
- uint8_t Pack = 0;
- // 綠 紅 藍(lán) 三原色分解
- Red0 = color0>>8;
- Green0 = color0>>16;
- Blue0 = color0;
- Red1 = color1>>8;
- Green1 = color1>>16;
- Blue1 = color1;
- // 計(jì)算需要多少步(取差值的最大值)
- RedMinus = Red1 - Red0;
- GreenMinus = Green1 - Green0;
- BlueMinus = Blue1 - Blue0;
- NStep = ( abs0(RedMinus) > abs0(GreenMinus) ) ? abs0(RedMinus):abs0(GreenMinus);
- NStep = ( NStep > abs0(BlueMinus) ) ? NStep:abs0(BlueMinus);
- // 計(jì)算出各色步進(jìn)值
- RedStep = (float)RedMinus / NStep;
- GreenStep = (float)GreenMinus / NStep;
- BlueStep = (float)BlueMinus / NStep;
- // 漸變開(kāi)始
- for (i = 0; i < NStep; i++) //燈點(diǎn)亮的個(gè)數(shù)可變
- {
- Red1 = Red0 + (int)(RedStep * i);
- Green1 = Green0 + (int)(GreenStep * i);
- Blue1 = Blue0 + (int)(BlueStep * i);
- color = Green1<<16 | Red1<<8 | Blue1; // 合成 綠紅藍(lán)
- WsDat[Pack] = color; //這里只第一個(gè)燈
- WS_L_SetAll(); // 輸出
- delay_ms(20); // 漸變速度
- if (Pack > nWs)
- {
- Pack = 0;
- }
- else
- {
- Pack++;
- }
- }
- // 漸變結(jié)束
- // return color;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: ColorToColor1
- * 功能說(shuō)明: 顏色漸變算法 (反向)
- * 形 參:color0、color1 從一種顏色變到別一種顏色
- * 返 回 值: color 變化后的顏色
- *********************************************************************************************************
- */
- void ColorToColor1(unsigned long color0, unsigned long color1)
- {
- unsigned char Red0, Green0, Blue0; // 起始三原色
- unsigned char Red1, Green1, Blue1; // 結(jié)果三原色
- int RedMinus, GreenMinus, BlueMinus; // 顏色差(color1 - color0)
- unsigned char NStep; // 需要幾步
- float RedStep, GreenStep, BlueStep; // 各色步進(jìn)值
- unsigned long color; // 結(jié)果色
- unsigned char i;
- int8_t Pack = nWs;
- // 綠 紅 藍(lán) 三原色分解
- Red0 = color0>>8;
- Green0 = color0>>16;
- Blue0 = color0;
- Red1 = color1>>8;
- Green1 = color1>>16;
- Blue1 = color1;
- // 計(jì)算需要多少步(取差值的最大值)
- RedMinus = Red1 - Red0;
- GreenMinus = Green1 - Green0;
- BlueMinus = Blue1 - Blue0;
- NStep = ( abs0(RedMinus) > abs0(GreenMinus) ) ? abs0(RedMinus):abs0(GreenMinus);
- NStep = ( NStep > abs0(BlueMinus) ) ? NStep:abs0(BlueMinus);
- // 計(jì)算出各色步進(jìn)值
- RedStep = (float)RedMinus / NStep;
- GreenStep = (float)GreenMinus / NStep;
- BlueStep = (float)BlueMinus / NStep;
- // 漸變開(kāi)始
- for (i = 0; i < NStep; i++) //燈點(diǎn)亮的個(gè)數(shù)可變
- {
- Red1 = Red0 + (int)(RedStep * i);
- Green1 = Green0 + (int)(GreenStep * i);
- Blue1 = Blue0 + (int)(BlueStep * i);
- color = Green1<<16 | Red1<<8 | Blue1; // 合成 綠紅藍(lán)
- WsDat[Pack] = color; //這里只第一個(gè)燈
- WS_H_SetAll(); // 輸出
- delay_ms(2); // 漸變速度
- if (Pack > 0)
- {
- Pack--;
- }
- else
- {
- Pack = nWs;
- }
- }
- // 漸變結(jié)束
- // return color;
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol1
- * 功能說(shuō)明: 從前向后移動(dòng)(單組)
- * 形 參:_uColor 點(diǎn)亮顏色
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol1(uint32_t _uColor, uint16_t _uTime)
- {
- uint8_t i;
- // for (i = 0; i < 3; i++)
- // {
- // _uColor = g_tSpi.RxBuf[0]<<16 | g_tSpi.RxBuf[1]<<8 | g_tSpi.RxBuf[2];
- //
- // //_uColor = _uColor + 0xfffff*i;
- // WsDat[ i] = _uColor;
- // // delay_ms(_uTime);
- [i]// //memset(WsDat, 0, sizeof(WsDat));[/i]
- [i]//[/i]
- [i]// }[/i]
- [i] WS_L_SetAll();[/i]
- [i] //delay_ms(_uTime);[/i]
- [i]}[/i]
- [i]/*[/i]
- [i]*********************************************************************************************************[/i]
- [i]* 函 數(shù) 名: WaterLampToCol2[/i]
- [i]* 功能說(shuō)明: 單組燈移位顯示[/i]
- [i]* 形 參:_uColor 點(diǎn)亮顏色[/i]
- [i]* _uTime 移位速度[/i]
- [i]* 返 回 值: 無(wú)[/i]
- [i]*********************************************************************************************************[/i]
- [i]*/[/i]
- [i]void WaterLampToCol2(uint32_t _uColor, uint16_t _uTime)[/i]
- [i]{[/i]
- [i] uint8_t i, j;[/i]
- [i] uint8_t Red2, Green2, Blue2; // 三原色[/i]
- [i] Red2 = _uColor>>8;[/i]
- [i] Green2 = _uColor>>16;[/i]
- [i] Blue2 = _uColor;[/i]
- [i] for (i = 0; i < nWs; i++)[/i]
- [i] {[/i]
- [i] for (j = 0; j < i; j++)[/i]
- [i] {[/i]
- [i] Red2 = Red2 + 0x22;[/i]
- [i] //Green2 = Green2 + 0x22;[/i]
- [i] //Blue2 = Blue2 + 0x22;[/i]
- [i] _uColor = Green2<<16 | Red2<<8 | Blue2;[/i]
- [i] // _uColor = _uColor + 0xfffff*i;[/i]
- [i] WsDat[j] = _uColor;[/i]
- [i] }[/i]
- [i] WS_L_SetAll();[/i]
- [i] delay_ms(_uTime);[/i]
- [i]// memset(WsDat, 0, sizeof(WsDat));[/i]
- [i] }[/i]
- [i]}[/i]
- [i]/*[/i]
- [i]*********************************************************************************************************[/i]
- [i]* 函 數(shù) 名: WaterLampToCol5[/i]
- [i]* 功能說(shuō)明: 與模式2反向[/i]
- [i]* 形 參:_uColor 點(diǎn)亮顏色[/i]
- [i]* _uTime 移位速度[/i]
- [i]* 返 回 值: 無(wú)[/i]
- [i]*********************************************************************************************************[/i]
- [i]*/[/i]
- [i]void WaterLampToCol5(uint32_t _uColor, uint16_t _uTime)[/i]
- [i]{[/i]
- [i] uint8_t i, j;[/i]
- [i] uint8_t Red2, Green2, Blue2; // 三原色[/i]
- [i] Red2 = _uColor>>8;[/i]
- [i] Green2 = _uColor>>16;[/i]
- [i] Blue2 = _uColor;[/i]
- [i] for (i = nWs; i > 0; i--)[/i]
- [i] {[/i]
- [i] for (j = i; j > 0; j--)[/i]
- [i] {[/i]
- [i] Red2 = Red2 + 0x22;[/i]
- [i] //Green2 = Green2 + 0x22;[/i]
- [i] //Blue2 = Blue2 + 0x22;[/i]
- [i] _uColor = Green2<<16 | Red2<<8 | Blue2;[/i]
- [i] // _uColor = _uColor + 0xfffff*i;[/i]
- [i] WsDat[j] = _uColor;[/i]
- [i] }[/i]
- [i] WS_L_SetAll();[/i]
- [i] delay_ms(_uTime);[/i]
- [i]// memset(WsDat, 0, sizeof(WsDat));[/i]
- [i] }[/i]
- [i]}[/i]
- [i]/*[/i]
- [i]*********************************************************************************************************[/i]
- [i]* 函 數(shù) 名: WaterLampToCol3[/i]
- [i]* 功能說(shuō)明: 從中點(diǎn)向兩端移動(dòng)[/i]
- [i]* 形 參:_uColor 點(diǎn)亮顏色[/i]
- [i]* _uTime 移位速度[/i]
- [i]* 返 回 值: 無(wú)[/i]
- [i]*********************************************************************************************************[/i]
- [i]*/[/i]
- [i]void WaterLampToCol3(uint32_t _uColor, uint16_t _uTime)[/i]
- [i]{[/i]
- [i] uint8_t i;[/i]
- [i] for (i = nWs/2; i < nWs; i++)[/i]
- [i] {[/i]
- [i] _uColor = _uColor + 0xfffff*i;[/i]
- [i] WsDat[i] = _uColor;[/i][/i]
- [i][i] WsDat[nWs/2 -(i - nWs/2)] = _uColor;[/i][/i]
- [i][i] WS_L_SetAll();[/i][/i]
- [i][i] delay_ms(_uTime);[/i][/i]
- [i][i] memset(WsDat, 0, sizeof(WsDat));[/i][/i]
- [i][i] }[/i][/i]
- [i][i]}[/i][/i]
- [i][i]/*[/i][/i]
- [i][i]*********************************************************************************************************[/i][/i]
- [i][i]* 函 數(shù) 名: WaterLampToCol4[/i][/i]
- [i][i]* 功能說(shuō)明: 從后向前移動(dòng)(單組)[/i][/i]
- [i][i]* 形 參:_uColor 點(diǎn)亮顏色[/i][/i]
- [i][i]* _uTime 移位速度[/i][/i]
- [i][i]* 返 回 值: 無(wú)[/i][/i]
- [i][i]*********************************************************************************************************[/i][/i]
- [i][i]*/[/i][/i]
- [i][i]void WaterLampToCol4(uint32_t _uColor, uint16_t _uTime)[/i][/i]
- [i][i]{[/i][/i]
- [i][i] int8_t i;[/i][/i]
- [i][i] for (i = nWs-1; i >= 0; i--)[/i][/i]
- [i][i] {[/i][/i]
- [i][i] _uColor = _uColor + 0xff0000*i + 0xff00*i + 0xff*i;[/i][/i]
- [i][i] WsDat[i] = _uColor;[/i][/i][/i]
- WS_L_SetAll();
- delay_ms(_uTime);
- memset(WsDat, 0, sizeof(WsDat));
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol6
- * 功能說(shuō)明: 從后向前移動(dòng)(跳一個(gè))
- * 形 參:_uColor 點(diǎn)亮顏色
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol6(uint32_t _uColor, uint16_t _uTime)
- {
- uint8_t i;
- for (i = 0; i < nWs; i++)
- {
- i = i + 1;
- //_uColor = _uColor + 0xfffff*i;
- WsDat[i] = _uColor;[/i]
- }
- WS_L_SetAll();
- delay_ms(_uTime);
- memset(WsDat, 0, sizeof(WsDat));
- for (i = 0; i < nWs; i++)
- {
- if(i != 0)
- {
- i = i + 1;
- }
- //_uColor = Color + 0xfffff*i;
- WsDat[i] = _uColor;[/i]
- }
- WS_L_SetAll();
- delay_ms(_uTime);
- memset(WsDat, 0, sizeof(WsDat));
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol7(可使用)
- * 功能說(shuō)明: 從后向前移動(dòng)(單組)
- * 形 參:_uColor0 顏色1
- * _uColor1 顏色2
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol7(uint32_t _uColor0, uint32_t _uColor1, uint16_t _uTime)
- {
- int8_t i, j, f = 0;
- uint8_t NStep; // 三原色
- unsigned char Red0, Green0, Blue0; // 起始三原色
- unsigned char Red1, Green1, Blue1; // 結(jié)果三原色
- int RedMinus, GreenMinus, BlueMinus; // 顏色差(color1 - color0) // 需要幾步
- float RedStep, GreenStep, BlueStep; // 各色步進(jìn)值
- Red0 = _uColor0>>8;
- Green0 = _uColor0>>16;
- Blue0 = _uColor0;
- Red1 = _uColor1>>8;
- Green1 = _uColor1>>16;
- Blue1 = _uColor1;
- NStep = 3;
- // 計(jì)算需要多少步(取差值的最大值)
- RedMinus = Red1 - Red0;
- GreenMinus = Green1 - Green0;
- BlueMinus = Blue1 - Blue0;
- // 計(jì)算出各色步進(jìn)值
- RedStep = (float)RedMinus / NStep;
- GreenStep = (float)GreenMinus / NStep;
- BlueStep = (float)BlueMinus / NStep;
- for(j = -(NStep);j < nWs; j++)
- {
- for(i = 0; i < NStep; i++)
- {
- Red1 = Red0 + (int)(RedStep * i);
- Green1 = Green0 + (int)(GreenStep * i);
- Blue1 = Blue0 + (int)(BlueStep * i);
- WsDat[i + j] = Green1<<16 | Red1<<8 | Blue1;
- }
- WS_L_SetAll();
- delay_ms(_uTime);
- memset(WsDat, 0, sizeof(WsDat));
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol8(可用)
- * 功能說(shuō)明: 從后向前移動(dòng)(跳一個(gè))
- * 形 參:_uColor 點(diǎn)亮顏色
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol8(uint32_t _uColor0, uint16_t _uTime)
- {
- uint8_t i;
- for (i = 3; i < nWs/2; i++)
- {
- WsDat[i] = _uColor0;[/i]
- }
- for (i = nWs/2; i < nWs - 3; i++)
- {
- WsDat[i] = 0;[/i]
- }
- WS_L_SetAll();
- delay_ms(_uTime);
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol9(可用)
- * 功能說(shuō)明: 從后向前移動(dòng)(跳一個(gè))
- * 形 參:_uColor 點(diǎn)亮顏色
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol9(uint32_t _uColor0, uint16_t _uTime)
- {
- uint8_t i;
- for (i = 3; i < nWs/2; i++)
- {
- WsDat[i] = 0;[/i]
- }
- for (i = nWs/2; i < nWs - 3; i++)
- {
- WsDat[i] = _uColor0;[/i]
- }
- WS_L_SetAll();
- delay_ms(_uTime);
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol10(可用)
- * 功能說(shuō)明: 從后向前移動(dòng)(跳一個(gè))
- * 形 參:_uColor 點(diǎn)亮顏色
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol10(uint32_t _uColor0,uint32_t _uColor1, uint16_t _uTime)
- {
- int8_t i, j;
- WsDat[1] = _uColor0;
- WsDat[0] = _uColor1;
- for(i = 0;i < nWs; i++)
- {
- WsDat[i + 2] = WsDat[i + 1];
- WsDat[i + 1] = WsDat[i];[/i]
- WsDat[i] = 0;[/i]
- WS_L_SetAll();
- delay_ms(_uTime);
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol11(可用)
- * 功能說(shuō)明: 從后向前移動(dòng)(跳一個(gè))
- * 形 參:_uColor 點(diǎn)亮顏色
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol11(uint32_t _uColor0,uint32_t _uColor1, uint16_t _uTime)
- {
- int8_t i, j;
- WsDat[1] = _uColor0;
- WsDat[0] = _uColor1;
- WsDat[nWs - 1] = _uColor0;
- WsDat[nWs - 2] = _uColor1;
- for(i = 0;i < nWs ; i++)
- {
- WsDat[i + 2] = WsDat[i + 1];
- WsDat[i + 1] = WsDat[i];[/i]
- WsDat[i] = 0;[/i]
- WsDat[nWs - i - 2] =WsDat[nWs - i - 1];
- WsDat[nWs - i - 1] = WsDat[nWs - 1];
- WsDat[nWs - 1] = 0;
- WS_L_SetAll();
- delay_ms(_uTime);
- }
- }
- /*
- *********************************************************************************************************
- * 函 數(shù) 名: WaterLampToCol12(可用)
- * 功能說(shuō)明: 從后向前移動(dòng)(跳一個(gè))
- * 形 參:_uColor 點(diǎn)亮顏色
- * _uTime 移位速度
- * 返 回 值: 無(wú)
- *********************************************************************************************************
- */
- void WaterLampToCol12(uint32_t _uColor0,uint32_t _uColor1, uint16_t _uTime)
- {
- unsigned char Red0, Green0, Blue0; // 起始三原色
- unsigned char Red1, Green1, Blue1; // 結(jié)果三原色
- unsigned char Red2, Green2, Blue2; // 結(jié)果三原色
- int RedMinus, GreenMinus, BlueMinus; // 顏色差(color1 - color0)
- unsigned char NStep; // 需要幾步
- float RedStep, GreenStep, BlueStep; // 各色步進(jìn)值
- unsigned long color; // 結(jié)果色
- unsigned char i, j;
- int8_t Pack = nWs;
- for(j = 0; j < 20 ;j++)
- {
- // 綠 紅 藍(lán) 三原色分解
- Red0 = _uColor0>>8;
- Green0 = _uColor0>>16;
- Blue0 = _uColor0;
- Red1 = _uColor1>>8;
- Green1 = _uColor1>>16;
- Blue1 = _uColor1;
- // 計(jì)算需要多少步(取差值的最大值)
- RedMinus = Red1 - Red0;
- GreenMinus = Green1 - Green0;
- BlueMinus = Blue1 - Blue0;
- NStep = ( abs0(RedMinus) > abs0(GreenMinus) ) ? abs0(RedMinus):abs0(GreenMinus);
- NStep = ( NStep > abs0(BlueMinus) ) ? NStep:abs0(BlueMinus);
- // 計(jì)算出各色步進(jìn)值
- RedStep = (float)RedMinus / NStep;
- GreenStep = (float)GreenMinus / NStep;
- BlueStep = (float)BlueMinus / NStep;
- WsDat[j-1] = 0 ;
- for(i = 0; i < NStep; i++)
- {
- Red2 = Red0 + (int)(RedStep * i);
- Green2 = Green0 + (int)(GreenStep * i);
- Blue2 = Blue0 + (int)(BlueStep * i);
- color = Green2<<16 | Red2<<8 | Blue2; // 合成 綠紅藍(lán)
- WsDat[j+1] = color ;
- WS_L_SetAll();
- delay_ms(_uTime);
- }
- for(i = 0; i < NStep; i++)
- {
- Red2 = Red1 - (int)(RedStep * i);
- Green2 = Green1 - (int)(GreenStep * i);
- Blue2 = Blue1 - (int)(BlueStep * i);
- color = Green2<<16 | Red2<<8 | Blue2; // 合成 綠紅藍(lán)
- WsDat[j] = color ;
- WS_L_SetAll();
- delay_ms(_uTime);
- }
- }
- }
復(fù)制代碼 |
|