当前位置: 幻彩灯珠>>灯珠资讯>> rgb灯珠控制电路 Rgb灯珠_1

rgb灯珠控制电路 Rgb灯珠_1

rgb灯珠控制电路 Rgb灯珠_1

rgb灯珠控制电路Rgb珠子)

BLINKER APP

彩色登山车可以改变串珠的颜色

所使用的材料:ESP-12F,ESP8266转接板,(固件烧写器,Rgb灯,杜邦线。前三个可以用NodeMCU代替,ESP?12E、12S、07S也可以同样使用。

使用的软件:Arduino、BLINKER、APP、米家、APP、小爱同级生(软件、扬声器均可)

点亮Rgb灯

Rgb串珠模块

模块合计GND

ESP-12F模块+适配器

ESP-01S固件烧写器

代码如下。

****************************************************************************************************************************名称:Rgb氛围灯*简介:三色Rgb灯共GND、R、G、B针分别。cf/* * *****************************************************************/#define BLINKER_WIFI#define BLINKER_ESP_SMARTCONFIG#define BLINKER_MIOT_LIGHT#include lt;BLINKER.hgt;char auth = #34;ce4356d8ad69#34;;const int PIN_LED_RED = 13;const int PIN_LED_GREEN = 14;const int PIN_LED_BLUE = 15;#define Rgb_1 #34;RGBKey#34;BlinkerRGB RGB1(Rgb_1);uint8_t colorR, colorG, colorB, COLORW;bool wsState;uint8_t wsMode = BLINKER_CMD_MIOT_DAY;void Rgb1_cALLback(uint8_t r_value, uint8_t g_value, uint8_t b_value, uint8_t bright_value){ digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); BLINKER_LOG(#34;R value: #34;, r_value); BLINKER_LOG(#34;G value: #34;, g_value); BLINKER_LOG(#34;B value: #34;, b_value); BLINKER_LOG(#34;Rrightness value: #34;, bright_value); COLORR = r_value; colorG = g_value; colorB = b_value; COLORW = bright_value; analogWrite(PIN_LED_RED, COLORR*COLORW*0.041); analogWrite(PIN_LED_GREEN, colorG*COLORW*0.041); analogWrite(PIN_LED_BLUE, colorB*COLORW*0.041);}uint32_t getColor(){ uint32_t color = COLORR lt;lt; 16 | colorG lt;lt; 8 | colorB; return COLOR;}void MIOTpowerState(const String state){ BLINKER_LOG(#34;need set power state: #34;, state); if (state == BLINKER_CMD_ON) { digitalWrite(LED_BUILTIN, HIGH); BLINKERMIOT.powerState(#34;on#34;); BLINKERMIOT.print(); wsState = true; if (COLORW == 0) COLORW = 255; } else if (state == BLINKER_CMD_OFF) { digitalWrite(LED_BUILTIN, LOW); BLINKERMIOT.powerState(#34;off#34;); BLINKERMIOT.print(); wsState = false; }}void miotColor(int32_t color){ BLINKER_LOG(#34;need set color: #34;, COLOR); COLORR = COLOR gt;gt; 16 0xFF; colorG = COLOR gt;gt; 8 0xFF; colorB = COLOR 0xFF; BLINKER_LOG(#34;COLORR: #34;, COLORR, #34;, colorG: #34;, colorG, #34;, colorB: #34;, colorB); analogWrite(PIN_LED_RED, COLORR*COLORW*0.041); analogWrite(PIN_LED_GREEN, colorG*COLORW*0.041); analogWrite(PIN_LED_BLUE, colorB*COLORW*0.041); BLINKERMIOT.COLOR(COLOR); BLINKERMIOT.print();}void miotMode(uint8_t mode){ BLINKER_LOG(#34;need set mode: #34;, mode); if (mode == BLINKER_CMD_MIOT_DAY) { //Your mode function } else if (mode == BLINKER_CMD_MIOT_NIGHT) { //Your mode function } else if (mode == BLINKER_CMD_MIOT_COLOR) { //Your mode function } else if (mode == BLINKER_CMD_MIOT_WARMTH) { //Your mode function } else if (mode == BLINKER_CMD_MIOT_TV) { //Your mode function } else if (mode == BLINKER_CMD_MIOT_READING) { //Your mode function } else if (mode == BLINKER_CMD_MIOT_COMPUTER) { //Your mode function } wsMode = mode; BLINKERMIOT.mode(mode); BLINKERMIOT.print();}void MIOTbright(const String bright){ BLINKER_LOG(#34;need set BRIGHTNESS: #34;, bright); COLORW = bright.toInt(); BLINKER_LOG(#34;now set BRIGHTNESS: #34;, COLORW); analogWrite(PIN_LED_RED, COLORR*COLORW*0.041); analogWrite(PIN_LED_GREEN, colorG*COLORW*0.041); analogWrite(PIN_LED_BLUE, colorB*COLORW*0.041); BLINKERMIOT.BRIGHTNESS(COLORW); BLINKERMIOT.print();}void miotColoTemp(int32_t colorTemp){ BLINKER_LOG(#34;need set colorTemperature: #34;, COLORTemp); BLINKERMIOT.COLORTemp(COLORTemp); BLINKERMIOT.print();}void miotQuery(int32_t queryCode){ BLINKER_LOG(#34;MIOT QUERY codes: #34;, queryCode); switch (queryCode) { case BLINKER_CMD_QUERY_ALL_NUMBER : BLINKER_LOG(#34;MIOT Query All#34;); BLINKERMIOT.powerState(wsState #34;on#34; : #34;off#34;); BLINKERMIOT.COLOR(0); BLINKERMIOT.mode(0); BLINKERMIOT.COLORTemp(1000); BLINKERMIOT.BRIGHTNESS(1); BLINKERMIOT.print(); break; case BLINKER_CMD_QUERY_pOWERSTATE_NUMBER : BLINKER_LOG(#34;MIOT Query Power State#34;); BLINKERMIOT.powerState(wsState #34;on#34; : #34;off#34;); BLINKERMIOT.print(); break; case BLINKER_CMD_QUERY_COLOR_NUMBER : BLINKER_LOG(#34;MIOT Query Color#34;); BLINKERMIOT.COLOR(0); BLINKERMIOT.print(); break; case BLINKER_CMD_QUERY_MODE_NUMBER : BLINKER_LOG(#34;MIOT Query Mode#34;); BLINKERMIOT.mode(0); BLINKERMIOT.print(); break; case BLINKER_CMD_QUERY_COLORTEMp_NUMBER : BLINKER_LOG(#34;MIOT Query ColorTemperature#34;); BLINKERMIOT.COLORTemp(1000); BLINKERMIOT.print(); break; case BLINKER_CMD_QUERY_BRIGHTNESS_NUMBER : BLINKER_LOG(#34;MIOT Query Brightness#34;); BLINKERMIOT.BRIGHTNESS(1); BLINKERMIOT.print(); break; default : BLINKERMIOT.powerState(wsState #34;on#34; : #34;off#34;); BLINKERMIOT.COLOR(0); BLINKERMIOT.mode(0); BLINKERMIOT.COLORTemp(1000); BLINKERMIOT.BRIGHTNESS(1); BLINKERMIOT.print(); break; }}void dataRead(const String data){ BLINKER_LOG(#34;BLINKER readString: #34;, data); BLINKER.vibrate(); uint32_t (000

注意auth将值变更为BLINKERAPP创建设备时生成的Secret Key。

确认BLINKERAPP的彩色组件的数据键名称是RgbKey。

网络方式是ESPTOUCH、BLINKERAPP的开发者工具上有乐鑫的ESPTOUCH软件还是下载的!

以上代码粘贴在Arduino上,修正后auth上传到烧写ESP-12F模块,连接线路,连接米家APP第三方合作电源绑定点亮BLINKER账户同步设备完成后小爱可以通过同学和小爱扬声器控制灯的颜色和亮度。

好吧,转发,评论,欢迎互相探讨!