小白求助本地开关由点动开关换成自锁开关程序
void sdms(){//BLINKER_LOG("本地开关动作!");
if (digitalRead(kg)==LOW&&digitalRead(kg2)==HIGH) { //
Blinker.delay(150);
if (digitalRead(kg2)==LOW){
BLINKER_LOG("设备已关闭!");
digitalWrite(kg,HIGH);
Button1.color("#FF0000");
Button1.text("设备已关闭");
Button1.print("off");
}
}
if (digitalRead(kg)==HIGH&&digitalRead(kg2)==HIGH) {
Blinker.delay(150);
if (digitalRead(kg2)==LOW){
BLINKER_LOG("设备已开启!");
digitalWrite(kg, LOW);
Button1.color("#0000FF");
Button1.text("设备已开启");
Button1.print("on");
}
}
}
你的程序写复杂了,如果点动非自锁,可以用
if(digitalRead(kg2) == HIGH){
digitalWrite(kg,!digitalRead(kg));
}
如果是自锁,你就不用管kg是什么状态,直接用kg2的状态赋值给kg就可以了
f(digitalRead(kg2) == HIGH){
digitalWrite(kg,HIGH);
*****
}
if(digitalRead(kg2) == LOW){
digitalWrite(kg,LOW);
***
}
页:
[1]