blinker控制RGB灯-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2735|回复: 0

[分享] blinker控制RGB灯

[复制链接]
发表于 2020-6-26 00:59 | 显示全部楼层 |阅读模式
本帖最后由 topdog 于 2020-7-29 00:31 编辑

有的三色灯是RGB分别接在esp8266三个管脚上控制的,随着blinker版本升级到0.3.4,手机APP版本到2.47,那么实际操作一下。手机控制端我选择了颜色col-yom控制键,上面圆形部分是颜色选择,下面直线是亮度选择(亮度最好不要拉到零)。另外还加了调试窗口,可以清楚看到红、绿、蓝和亮度的参数变化。

blinker_4_pin_rgb.jpg


程序如下:

#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();
}

(完)




您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 09:28 , Processed in 0.165312 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表