其他分享
首页 > 其他分享> > 2020-05-02

2020-05-02

作者:互联网

//blinker和小爱配置程序
#define BLINKER_PRINT Serial
#define BLINKER_MIOT_OUTLET
#define BLINKER_WIFI

#include<Blinker.h>

char auth[]=“点灯科技密钥”;
char ssid[]=“无线名称”;
char pswd[]=“无线密码”;

//新建组建对象
BlinkerButton Button1(“yy”);

int Pin1=0; //定义I/O口

//按下按键即会执行该函数
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ",state);
if(state==“on”)
{
digitalWrite(Pin1,HIGH);
Button1.print(“on”);

}

else if(state==“off”)
{
digitalWrite(Pin1, LOW);
Button1.print(“off”);
}
}

void miotPowerState(const String & state) //小爱同学执行回调函数
{
BLINKER_LOG("need set power state: ", state);

if (state == BLINKER_CMD_ON) {
    digitalWrite(Pin1, HIGH);
    
    BlinkerMIOT.powerState("on");
    Button1.print("on");
    BlinkerMIOT.print();
}
else if (state == BLINKER_CMD_OFF) {
    digitalWrite(Pin1,LOW);

    BlinkerMIOT.powerState("off");
    Button1.print("off");
    BlinkerMIOT.print();
}

}

void setup()
{
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);

// 初始化有LED的IO
pinMode(Pin1, OUTPUT);
digitalWrite(Pin1, LOW);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);

BlinkerMIOT.attachPowerState(miotPowerState);  //小爱同学注册回调函数

Button1.attach(button1_callback);

}

void loop() {
Blinker.run();
}

附页2
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Servo.h>
#include <Blinker.h>

char auth[] = “fbfb8024b197”;
char ssid[] = “MERCURY_CA24”;
char pswd[] = “66668888”;

Servo myservo;

#define BUTTON_1 “btn-abc”

BlinkerButton Button1(BUTTON_1); //定义3个按钮

void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
if (state == BLINKER_CMD_ON)
{
myservo.write(180);
Button1.print(“on”);
}

else if (state == BLINKER_CMD_OFF)

{
myservo.write(0);
Button1.print(“off”);
}
}

void setup()
{
//初始化串口//
Serial.begin(115200);
#if de

求大神给我解读一下这两段程序,拜托了

标签:02,BLINKER,05,void,Button1,state,2020,print,Pin1
来源: https://blog.csdn.net/FAB412/article/details/105894498