Button state

Hello!
Help me with the problem: there is a code

BLYNK_WRITE(V1) {  // Called whenver setting Time Input Widget
          TimeInputParam t(param);
          SThour = t.getStartHour();
          STmin = t.getStartMinute();
          STsec = t.getStartSecond();
          SPhour = t.getStopHour();
          SPmin = t.getStopMinute();
          SPsec = t.getStopSecond();
          }

      void TimeCheck() {  // call with timer every 30 seconds or so
        // Get RTC time
        sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
        Serial.print("Current Time: ");
        Serial.println(currentTime);
      
        // Get Time Input Widget time
        sprintf(startTime, "%02d:%02d:%02d", SThour, STmin, STsec);
        Serial.print("Start Time: ");
        Serial.println(startTime);
      
        sprintf(startTime, "%02d:%02d:%02d", SPhour, SPmin, SPsec);
        Serial.print("Stop Time: ");
        Serial.println(startTime);
      
        if (hour() == SThour) {
          if (minute() == STmin) {
            Serial.println("Doing something now");
            digitalWrite(RELE, LOW); // включаем реле
            Blynk.setProperty(V4, "offLabel", "");
            led1.on();// включаем подтверждающую лампочку
          } else if (minute() < STmin) {
            Serial.println("Will do something");
          } else if (minute() > STmin) {
            Serial.println("Did something");
          } else {
            Serial.println("Clueless");
          }
        }
      
        if (hour() == SPhour) {
          if (minute() == SPmin) {
            Serial.println("Stopping something now");
            digitalWrite(RELE, HIGH); // отключаем реле
            Blynk.setProperty(V4, "onLabel", "");
            led1.off();// выключаем лампочку
          } else if (minute() < SPmin) {
            Serial.println("Will stop something");
          } else if (minute() > SPmin) {
            Serial.println("Stopped something");
          } else {
            Serial.println("Clueless");
          }
        }
        Serial.println("----------");
      }
      
    BLYNK_WRITE(V4) {
     // int buttonState = param.asInt();
      rele = param.asInt();
      digitalWrite(RELE, rele);
      if (rele == 0) {//проверим состояние.
           led1.on(); //вкл вирт.светодиод
      }
      else { //иначе выключим
          led1.off();
      }
    }

In it relay can be turned on both through Time Widget and Button Widget. I made sure that the led shows the status of the relay (on/off) but I do not know how to make the state of the button displays the current state of the relay. I mean, if the relay is turned on using the Time Widget button should change its state. Is it possible to implement this?
Thanks!

Use Blynk virtual write to update the button status

I just recently used this exact type of example for another topic… How to use two widgets on same digital pin - #3 by Gunner

But I will paste it here as well.


E.g. For simplicity, I am just using a using a Button Widget (set to Switch mode) on V0 and the Timer Widget on V1 to turn ON or OFF the same LED on a digital pin (including feedback to the Button when the timer kicks in :wink: ) Assuming built in LED on Arduino’s pin 13

BLYNK_WRITE(V0) { // Button Widget function
digitalWrite(13, param.asInt()); // take the state of the Button and send it to the pin
}

BLYNK_WRITE(V1) { // Timer Widget function
digitalWrite(13, param.asInt()); // take the state of the Timer and send it to the pin
Blynk.virtualWrite(V0, param.asInt()); // Send timer state back to button to update it.
}
1 Like