int to bool
This commit is contained in:
@@ -29,7 +29,7 @@ unsigned long cRun;
|
||||
Bounce l1 = Bounce();
|
||||
Bounce l2 = Bounce();
|
||||
|
||||
bool switchLight(uint8_t nLamp, int state, bool pub);
|
||||
bool switchLight(uint8_t nLamp, bool state, bool pub);
|
||||
void connectToWifi();
|
||||
void connectToMqtt();
|
||||
void onWifiConnect(const WiFiEventStationModeGotIP& event);
|
||||
@@ -110,12 +110,12 @@ void loop() {
|
||||
l1.update();
|
||||
l2.update();
|
||||
if(l1.fell()){
|
||||
switchLight(R_LED1, !digitalRead(R_LED1), true);
|
||||
//lStat1 = !lStat1;
|
||||
switchLight(R_LED1, !lStat1, true);
|
||||
lStat1 = !lStat1;
|
||||
}
|
||||
if(l2.fell()){
|
||||
switchLight(R_LED2, !digitalRead(R_LED2), true);
|
||||
//lStat2 = !lStat2;
|
||||
switchLight(R_LED2, !lStat2, true);
|
||||
lStat2 = !lStat2;
|
||||
}
|
||||
// if(lStat1 != oldLStat1){
|
||||
// digitalWrite(R_LED1, lStat1);
|
||||
@@ -145,7 +145,7 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
bool switchLight(uint8_t nLamp, int state, bool pub)
|
||||
bool switchLight(uint8_t nLamp, bool state, bool pub)
|
||||
{
|
||||
digitalWrite(nLamp, state);
|
||||
EEPROM.put(nLamp == R_LED1 ? 0 : 1, state);
|
||||
@@ -192,16 +192,16 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
|
||||
if(String(topic) == "/home/bigroom/lamp1"){
|
||||
|
||||
// if (atoi(payload) == 1) switchLight(R_LED1, 1, false);
|
||||
if (strcmp("true", payload) == 0) switchLight(R_LED1, 1, false);
|
||||
if (strcmp("true", payload) == 0) switchLight(R_LED1, true, false);
|
||||
//lStat1 = true;
|
||||
else switchLight(R_LED1, 0, false);
|
||||
else switchLight(R_LED1, false, false);
|
||||
//lStat1 = false;
|
||||
//rcv = true;
|
||||
}
|
||||
if(String(topic) == "/home/bigroom/lamp2"){
|
||||
if (strcmp("true", payload) == 0) switchLight(R_LED2, 1, false);
|
||||
if (strcmp("true", payload) == 0) switchLight(R_LED2, true, false);
|
||||
//if (atoi(payload) == 1) switchLight(R_LED2, 1, false);
|
||||
//lStat1 = true;
|
||||
else switchLight(R_LED2, 0, false);
|
||||
else switchLight(R_LED2, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user