|
本帖最后由 topdog 于 2020-7-29 00:31 编辑
有的三色灯是RGB分别接在esp8266三个管脚上控制的,随着blinker版本升级到0.3.4,手机APP版本到2.47,那么实际操作一下。手机控制端我选择了颜色col-yom控制键,上面圆形部分是颜色选择,下面直线是亮度选择(亮度最好不要拉到零)。另外还加了调试窗口,可以清楚看到红、绿、蓝和亮度的参数变化。
程序如下:
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "blinker密码";
char ssid[] = "wifi名称";
char pswd[] = "wifi密码";
#define RGB_1 "col-yom"
const int PIN_LED_BLUE = 13;
const int PIN_LED_RED = 14;
const int PIN_LED_GREEN = 15;
int red, green, blue, bright = 0;
BlinkerRGB RGB1(RGB_1);
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("R value: ", r_value);
BLINKER_LOG("G value: ", g_value);
BLINKER_LOG("B value: ", b_value);
BLINKER_LOG("Rrightness value: ", bright_value);
int bright = bright_value;
int red = map(r_value, 0, bright, 1024, 0);
int blue = map(b_value, 0, bright, 1024, 0);
int green = map(g_value, 0, bright, 1024, 0);
analogWrite(PIN_LED_BLUE, blue);
analogWrite(PIN_LED_RED, red);
analogWrite(PIN_LED_GREEN, green);
Blinker.delay(500);
}
void dataRead(const String &data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
RGB1.brightness(random(0, 255));
RGB1.print(random(0, 255), random(0, 255), random(0, 255));
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(PIN_LED_BLUE, OUTPUT);
pinMode(PIN_LED_RED, OUTPUT);
pinMode(PIN_LED_GREEN, OUTPUT);
digitalWrite(PIN_LED_BLUE, HIGH);
digitalWrite(PIN_LED_RED, HIGH);
digitalWrite(PIN_LED_GREEN, HIGH);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
RGB1.attach(rgb1_callback);
}
void loop()
{
Blinker.run();
}
(完)
|
|