求大神看看这是什么问题'D1' was not declared in this scope
本帖最后由 chengliang7851 于 2020-3-2 12:26 编辑#define BLINKER_WIFI
#define BLINKER_MIOT_MULTI_OUTLET //设置为小爱多个插座的模式
#include <Blinker.h>
BlinkerButton Button1("btn-km"); //设置blinkerapp内数据键名
BlinkerButton Button2("btn-kckm"); //这里只用了其中三个
BlinkerButton Button3("btn-gckm");
BlinkerText Text1("text_1");
char i;
char auth[] = "******";
char ssid[] = "******";
char pswd[] = "******";
bool oState = { false }; //设置5路开关控制
void miotPowerState(const String & state, uint8_t num) //小爱同学控制指令
{
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
if(num==1){
i=D1; //指定每一路开关对应在开发板上的通道接口
}else if(num==2){
i=D2;
}else if(num==3){
i=D5;
}
if (state == BLINKER_CMD_ON) {
digitalWrite(i, HIGH); //这里控制模式都是点动模式
Blinker.delay(200); //高电平触发继电器200毫秒后低电平断开继电器
digitalWrite(i, LOW);
BlinkerMIOT.powerState("on", num);
BlinkerMIOT.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(i, HIGH);
Blinker.delay(200);
digitalWrite(i, LOW);
BlinkerMIOT.powerState("off", num);
BlinkerMIOT.print();
oState = false;
if (num == 0)
{
for (uint8_t o_num = 0; o_num < 5; o_num++)
{
oState = false;
}
}
}
}
void miotQuery(int32_t queryCode, uint8_t num)
{
BLINKER_LOG("AliGenie Query outlet: ", num,", codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(oState ? "on" : "off", num);
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(oState ? "on" : "off", num);
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? "on" : "off", num);
BlinkerMIOT.print();
break;
}
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void button1_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D1, HIGH);
Blinker.delay(200);
digitalWrite(D1, LOW);
Blinker.print("开门命令已经处理");
Text1.print("shuju");
}
void button2_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D2, HIGH);
Blinker.delay(400);
Blinker.print("开车库门已经处理");
digitalWrite(D2, LOW);
}
void button3_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(D5, HIGH);
Blinker.delay(300);
Blinker.print("关车库门已经处理");
digitalWrite(D5, LOW);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(D1, OUTPUT); 没D1的不是这个范围中声明 digitalWrite(D1, LOW);
pinMode(D2, OUTPUT);
digitalWrite(D2, LOW);
pinMode(D5, OUTPUT);
digitalWrite(D5, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
}
void loop()
{
Blinker.run();
D1没定义。IO输入输出直接1就行了,不用D1 验证 时出现这个问题 D1' was not declared in this scope chengliang7851 发表于 2020-3-2 12:27
验证 时出现这个问题 D1' was not declared in this scope
程序中D1,D2,D5,直接写板子对应的GPIO口数字即可. Creeper666 发表于 2020-3-2 13:51
D1没定义。IO输入输出直接1就行了,不用D1
D1不等于GPIO1,得根据实际来确定 n1001 发表于 2020-3-2 15:51
D1不等于GPIO1,得根据实际来确定
抱歉,说错了 对照gpio和d脚的关系, lwq1947 发表于 2020-3-2 14:58
程序中D1,D2,D5,直接写板子对应的GPIO口数字即可.
还有个问题,这个代码我也是档的别人,怎么把点动改自锁。我改下还是点动 dadv 发表于 2020-3-2 19:52
对照gpio和d脚的关系,
还有个问题,这个代码我也是档的别人,怎么把点动改自锁。我改下还是点动 chengliang7851 发表于 2020-3-3 14:47
还有个问题,这个代码我也是档的别人,怎么把点动改自锁。我改下还是点动 ...
继电器该接法
页:
[1]
2