esp8266+点灯APP+小爱控制WS2812灯带颜色和亮度
/*点灯APP+小爱控制WS2812灯带 20201年8月28日
功能:
1、用点灯APP控制灯带颜色
2、用小爱同学控制灯带颜色
材料:
ESP8266
WS2812灯带
220V转5V供电模块
作者:九洲创客
QQ:353529281
*/
#define BLINKER_WIFI//WIFI库
#define BLINKER_MIOT_LIGHT//小爱控制颜色库
#define BLINKER_MIOT_MULTI_OUTLET //小爱控制亮度库
#include <Blinker.h>//点灯库
char auth[] = "XXXXX"; //点灯KEY
char ssid[] = "XXXXX"; //家里WIFI账号
char pswd[] = "XXXXX";//这里WIFI密码
//WS2812B库
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN D4 //控制灯带的IO脚
#define NUMPIXELS 16 //灯带数量
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//点灯APP调色板
#define RGB_1 "col-deng"
BlinkerRGB Deng1(RGB_1);
//申明RGB色和亮度
int8_t colorR, colorG, colorB, colorW;
//设置每一个灯带的颜色和亮度
void pixelShow()
{
pixels.setBrightness(colorW);
for(int i = 0; i < NUMPIXELS; i++){
pixels.setPixelColor(i, colorR, colorG, colorB);
}
pixels.show();
}
//小爱控制颜色
void miotColor(int32_t color)
{
BLINKER_LOG("need set color: ", color);
colorR = color >> 16 & 0xFF;
colorG = color >>8 & 0xFF;
colorB = color & 0xFF;
BLINKER_LOG("colorR: ", colorR, ", colorG: ", colorG, ", colorB: ", colorB);
pixels.clear();
pixels.setBrightness(colorW);
for(int i = 0; i < NUMPIXELS; i++){
pixels.setPixelColor(i, colorR, colorG, colorB);
}
pixels.show();
BlinkerMIOT.color(color);
BlinkerMIOT.print();
}
//小爱控制亮度
void miotBright(const String & bright)
{
BLINKER_LOG("need set brightness: ", bright);
colorW = bright.toInt();
BLINKER_LOG("now set brightness: ", colorW);
pixelShow();
BlinkerMIOT.brightness(colorW);
BlinkerMIOT.print();
}
//点灯APP控制颜色和亮度
void deng1_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("R value: ", r_value);
BLINKER_LOG("G value: ", g_value);
BLINKER_LOG("B value: ", b_value);
BLINKER_LOG("Rrightness value: ", bright_value);
colorR = r_value;
colorG = g_value;
colorB = b_value;
colorW = bright_value;
pixelShow();
}
void setup()
{
//串口输出状态
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
//初始化颜色和亮度
colorR = 255;
colorG = 255;
colorB = 255;
colorW = 100;
pixels.begin();
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Deng1.attach(deng1_callback);
BlinkerMIOT.attachColor(miotColor);
BlinkerMIOT.attachBrightness(miotBright);
}
void loop()
{
Blinker.run(); //点灯科技运行
}
BlinkerMIOT.attachColor(miotColor); BlinkerMIOT.attachBrightness(miotBright)也两行函数什么意思呀?大神 学好c语言 发表于 2021-10-4 19:29
BlinkerMIOT.attachColor(miotColor); BlinkerMIOT.attachBrightness(miotBright)也两行函数什么意 ...
看起来像是初始化小爱控制相关函数的
页:
[1]