From 50b11b44f5911837c6fb06a7302b14a5687d8d32 Mon Sep 17 00:00:00 2001 From: lexa Date: Sat, 28 Nov 2020 18:10:40 +0300 Subject: [PATCH] int to bool --- Sw_BigRoom/src/main.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sw_BigRoom/src/main.cpp b/Sw_BigRoom/src/main.cpp index 24c35bc..3987890 100644 --- a/Sw_BigRoom/src/main.cpp +++ b/Sw_BigRoom/src/main.cpp @@ -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); } }