如何用blinker做esp32呼吸灯
如题,想用blinker的调色板获取led灯颜色,然后按一下按键led从当前颜色由亮到灭再由灭到亮,关键要求led在亮灭时如果收到颜色改变信号能随时打断亮灭直接变色。
这个程序我用蓝牙做过现在用blinker就不会了,
如何在blinker呼吸灯延时时时刻监听led是否变色?
本帖最后由 wanglanshu 于 2020-4-21 16:55 编辑
你们这些不靠谱的家伙,最后还是要我亲自试着弄好了,原来blinker的滑动条按键。。什么的类似于Arduino的外部中断,
你主程序写个while(1)跑死按按钮时也依旧会转入按钮程序,
所以不用担心主程序跑呼吸灯时会不会卡在while里无法接受按键信号,
另外esp32居然没有analogwrite函数下面贴代码
#define BLINKER_WIFI //联网模式,分别有蓝牙,WIFI,和MQTT,我的是WIFI,所以我写BLINKER_WIFI
#include <Blinker.h> //blinker库
#define RGB"rgb-4gv" //定义RGB组件,这里的名字必须和手机APP里的RGB组件名一样
#define kaiguan "tog-cac" //定义滑动开关组件,这里的名字必须和手机APP里的滑动开关组件名一样
#define BUTTON_1 "breath" //定义按钮组件,这里的名字必须和手机APP里的按钮组件名一样
#define TAP_EXAMPLE //这个我也不知道
#define r 4 //定义8266的GIPO4为红色灯的输出
#define g 5 //定义8266的GIPO5为绿色灯的输出
#define b 13 //定义8266的GIPO13为蓝色灯的输出
#define timeup 30 //50ms
char auth[] = "XXXXXXXXXXX";
char ssid[] = "XXXXXXXXXXX";
char pswd[] = "XXXXXXXXXX";
#define Slider_1 "rslider"
#define Slider_2 "gslider"
#define Slider_3 "bslider"
BlinkerSlider Slider1(Slider_1);
BlinkerSlider Slider2(Slider_2);
BlinkerSlider Slider3(Slider_3);
BlinkerButton Button1(BUTTON_1);
byte rcolor = 0, gcolor = 0, bcolor = 0;
byte rtemp=0,gtemp=0,btemp=0;
bool breathopen = false;
int clc = 0;
void slider1_callback(int32_t value)
{
BLINKER_LOG("get rslider value: ", value);
rcolor = value;
ledcWrite(0, rcolor);
}
void slider2_callback(int32_t value)
{
BLINKER_LOG("get gslider value: ", value);
gcolor = value;
ledcWrite(1, gcolor);
}
void slider3_callback(int32_t value)
{
BLINKER_LOG("get bslider value: ", value);
bcolor = value;
ledcWrite(2, bcolor);
}
void button1_callback(const String & state)
{
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
breathopen = !breathopen;
BLINKER_LOG("get button state: ", breathopen);
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
//pinMode(r, OUTPUT); //设置R为输出;这里的R==上面的GPIO4也就是设置GPIO4为输出模式
//pinMode(g, OUTPUT); //同上
//pinMode(b, OUTPUT); //同上
ledcSetup(0, 312500, 8);
ledcAttachPin(r, 0);
ledcSetup(1, 312500, 8);
ledcAttachPin(g, 1);
ledcSetup(2, 312500, 8);
ledcAttachPin(b, 2);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Slider1.attach(slider1_callback);
Slider2.attach(slider2_callback);
Slider3.attach(slider3_callback);
Button1.attach(button1_callback);
Blinker.run();
}
void loop()
{
// clc = timeup;
// while ((clc >= 0))
// {
// ledcWrite(0, clc * rcolor / timeup);
// ledcWrite(1, clc * gcolor / timeup);
// ledcWrite(2, clc * bcolor / timeup);
//// Button1.attach(button1_callback);
// Blinker.delay(50);
// clc--;
// }
if (breathopen == false)
{
Slider1.attach(slider1_callback);
Slider2.attach(slider2_callback);
Slider3.attach(slider3_callback);
Button1.attach(button1_callback);
BLINKER_LOG("nobreath ",0);
Blinker.delay(50);
}
else if (breathopen == true)
{
BLINKER_LOG("breath ",0);
clc = timeup;
while ((clc >= 0) && (breathopen == true))
{
ledcWrite(0, clc * rcolor / timeup);
ledcWrite(1, clc * gcolor / timeup);
ledcWrite(2, clc * bcolor / timeup);
// ledcWrite(0, 255);
// ledcWrite(1,255);
// ledcWrite(2, 255);
BLINKER_LOG("clc ",clc);
Button1.attach(button1_callback);
Blinker.delay(50);
clc--;
}
clc = 0;
while ((clc <= timeup) && (breathopen == true))
{
ledcWrite(0, clc * rcolor / timeup);
ledcWrite(1, clc * gcolor / timeup);
ledcWrite(2, clc * bcolor / timeup);
Button1.attach(button1_callback);
Blinker.delay(50);
clc++;
}
}
}
能动起来吗? weiqinglong51 发表于 2020-9-13 18:09
能动起来吗?
当然能,我不但试过还拍了视频 wanglanshu 发表于 2020-9-13 19:25
当然能,我不但试过还拍了视频
6666666666666 arduino 引脚定义的资料在哪里找到的呀
页:
[1]