+EDP协议的麒麟座控制WS2812幻彩灯条,实现任意颜色
时间:10-02
整理:3721RD
点击:
本测试使用onenet云平台,实现网页或手机端对幻彩灯条的颜色控制。1,WS2812简介
2,程序更改
a,增加控制幻彩灯条颜色的数据流,如下
- //数据流
- DATA_STREAM dataStream[] = {
- {"colourlight_r", &rgbStatus.lightrSta, TYPE_UCHAR, 1},
- {"colourlight_g", &rgbStatus.lightgSta, TYPE_UCHAR, 1},
- {"colourlight_b", &rgbStatus.lightbSta, TYPE_UCHAR, 1},
- {"Red_Led", &ledStatus.Led4Sta, TYPE_BOOL, 1},
- {"Green_Led", &ledStatus.Led5Sta, TYPE_BOOL, 1},
- {"Yellow_Led", &ledStatus.Led6Sta, TYPE_BOOL, 1},
- {"Blue_Led", &ledStatus.Led7Sta, TYPE_BOOL, 1},
- {"beep", &beepInfo.Beep_Status, TYPE_BOOL, 1},
- {"temperature", &sht20Info.tempreture, TYPE_FLOAT, 1},
- {"humidity", &sht20Info.humidity, TYPE_FLOAT, 1},
- {"Xg", &adxlInfo.incidence_Xf, TYPE_FLOAT, 1},
- {"Yg", &adxlInfo.incidence_Yf, TYPE_FLOAT, 1},
- {"Zg", &adxlInfo.incidence_Zf, TYPE_FLOAT, 1},
- {"errType", &faultTypeReport, TYPE_UCHAR, 1},
- };
b,WS2812驱动文件 rgbled.c
- //μ¥???úí·???t
- #include "stm32f10x.h"
- //LEDí·???t
- #include "rgb_led.h"
- RGB_STATUS rgbStatus;
- /*
- ************************************************************
- * oˉêy??3?£o Led_Init
- *
- * oˉêy1|?ü£o LED3?ê??ˉ
- *
- * è??ú2?êy£o ?T
- *
- * ·μ??2?êy£o ?T
- *
- * ?μ?÷£o LED4-PC7 LED5-PC8 LED6-PA12 LED7-PC10
- ??μ???1?μ? μíμ????aμ?
- ************************************************************
- */
- void RGB_Led_Init(void)
- {
-
- GPIO_InitTypeDef gpioInitStrcut;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //′ò?aGPIOAoíGPIOCμ?ê±?ó
-
- gpioInitStrcut.GPIO_Mode = GPIO_Mode_Out_PP; //éè???aí?íìê?3??£ê?
- gpioInitStrcut.GPIO_Pin = GPIO_Pin_1; //3?ê??ˉPin7?¢8?¢10
- gpioInitStrcut.GPIO_Speed = GPIO_Speed_50MHz; //3D??μ?×?′ó?μ?ê
- GPIO_Init(GPIOA, &gpioInitStrcut); //3?ê??ˉGPIOC
-
- }
- void Delay(__IO u32 nCount) //?òμ¥μ??óê±oˉêy
- {
- for(; nCount != 0; nCount--);
- }
- /******************************************************************/
- /* êy?Y′?ê?800Koˉêy */
- /******************************************************************/
- void send_dat(u8 dat) //?????è′?
- {
- unsigned char a;
- for(a=0;a<8;a++) //6201 a=8; 6205 a=12
- {
- if(dat&0x80) //6201 dat & 0x80; 6205 dat & 0x800
- {
- GPIO_SetBits(GPIOA, GPIO_Pin_1);
- Delay(0x000001);
- GPIO_ResetBits(GPIOA, GPIO_Pin_1);
- }
- else
- {
- GPIO_SetBits(GPIOA, GPIO_Pin_1);
- __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
- GPIO_ResetBits(GPIOA, GPIO_Pin_1);
- __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop(); __nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();__nop();
- }
- dat <<=1; //dat×óò?1??
- }
- }
- /******************************************************************/
- /* reset??oˉêy */
- /******************************************************************/
- void reset ()
- {
- GPIO_ResetBits(GPIOA, GPIO_Pin_1);
- Delay(0x00013F);
- }
- /******************************************************************/
- /* í?2???é???ê?oˉêy */
- /******************************************************************/
- void send_tongbu(unsigned char R_lever, unsigned char G_lever, unsigned char B_lever)
- {
- unsigned char n;
- for(n=20;n>0;n--)
- {
- send_dat(R_lever);
- send_dat(G_lever);
- send_dat(B_lever);
- }
-
- reset();
- rgbStatus.lightrSta = R_lever;
- rgbStatus.lightgSta = G_lever;
- rgbStatus.lightbSta = B_lever;
- }
c,rgbled.h
- #ifndef _RGB_LED_H_
- #define _RGB_LED_H_
- typedef struct
- {
- unsigned char lightrSta;
- unsigned char lightgSta;
- unsigned char lightbSta;
- } RGB_STATUS;
- extern RGB_STATUS rgbStatus;
- void RGB_Led_Init(void);
- void send_tongbu(unsigned char R_lever,unsigned char G_lever,unsigned char B_lever);
- #endif
左边5个按钮使灯条呈现固定的5种颜色,并将颜色值在右边旋钮显示,右边的旋钮可以让灯条表现出任意颜色
4,成果展示
a,按钮控制
b,旋钮控制1
c,旋钮控制2
关于onenet云平台,控制有明显延时,还有就是应用的数据刷新频率最快为3秒这也是时间太长了。
来看看小编怎么玩的
板子非常不错,顶一下
小编软件可以分享一下吗