|
目前关于blinker滑块应用的例程并不多,通过学习blinker滑块示例程序以及在奈何老师的指导下终于试成了用blinker滑块来控制单个LED灯的亮暗.照猫画虎近而
实现了用三个滑块控制RGB三色LED灯亮度和色彩.程序如下:
#define BLINKER_WIFI
#include <Blinker.h>
char auth[]="efca902628e4";
char ssid[]="*******";
char pswd[]="**********";
#define Slider_1 "SliderKey1"
#define Slider_2 "SliderKey2"
#define Slider_3 "SliderKey3"
BlinkerSlider Slider1(Slider_1);
BlinkerSlider Slider2(Slider_2);
BlinkerSlider Slider3(Slider_3);
int i=0,j=0,k=0;
void slider1_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
i=value;
}
void slider2_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
j=value;
}
void slider3_callback(int32_t value)
{
BLINKER_LOG("get slider value: ", value);
k=value;
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
pinMode(D5,OUTPUT);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Slider1.attach(slider1_callback);
Slider2.attach(slider2_callback);
Slider3.attach(slider3_callback);
}
void loop()
{
analogWrite(D3,i);//R
analogWrite(D4,j);//G
analogWrite(D5,k);//B
Blinker.run();
}
补充说明的是blinker app上各滑块数值大小为0-1000,我用的arduino板是wemos d1.PWM端口输出最大电压为3V不能达到蓝绿LED电压的要求同时RGB三色LED灯品种
功率不同所以要通8050三极管放大电流驱动RGB三色LED灯.此例程仅供参考不当之处恳请大家批评指正.
|
|