用nodemcu控制四路继电器,想实现三路双击效果,一路单击效果
代码如下
#define BLINKER_WIFI
#define BLINKER_MIOT_MULTI_OUTLET
#include <Blinker.h>
BlinkerButton Button1("btn-1");
BlinkerButton Button2("btn-2");
BlinkerButton Button3("btn-3");
BlinkerButton Button4("btn-4");
char i;
char j;
char auth[] = "9b3f1ec4ae0c";
char ssid[] = "2.4G";
char pswd[] = "123456789";
bool oState[5] = { false };
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;
}else if(num==4){
j=D6;
}
if (state == BLINKER_CMD_ON) {
digitalWrite(i, HIGH);
Blinker.delay(150);
digitalWrite(i, LOW);
Blinker.delay(150);
digitalWrite(i, HIGH);
Blinker.delay(150);
digitalWrite(i, LOW);
digitalWrite(j, HIGH);
Blinker.delay(150);
digitalWrite(j, LOW);
BlinkerMIOT.powerState("on", num);
BlinkerMIOT.print();
oState[num] = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(i, HIGH);
Blinker.delay(150);
digitalWrite(i, LOW);
Blinker.delay(150);
digitalWrite(i, HIGH);
Blinker.delay(150);
digitalWrite(i, LOW);
digitalWrite(j, HIGH);
Blinker.delay(150);
digitalWrite(j, LOW);
BlinkerMIOT.powerState("off", num);
BlinkerMIOT.print();
oState[num] = false;
if (num == 0)
{
for (uint8_t o_num = 0; o_num < 5; o_num++)
{
oState[o_num] = false;
}
}
}
}
手机APP操作是正常的
但是用小爱同学,通电第一次叫,每个通道都正常,可以实现123双击,4单击
第二次叫小爱同学,就会乱跳
比如说我先叫了一通道,一通道快速吸和两次,再叫四通道,一通道就会先跳两次,四通道在跳一次
通电先叫四通道,四通道正常只跳一次,在叫其他通道,四通道也会跟着跳
请问大神应该怎么去写代码
|