[SOLVED] Logical Operator in Blynk. IF 2 virtual pin High then

Hi all,
I’m trying to put in place an if clausole that check different virtual pins status.

IF virtual pin V20 and V11 are hight do an action.
Please consider that one virtual pin is in swich mode and the other one is in push mode.

Here my code

BLYNK_WRITE(V20) // ON/OFF
{
  int pinValueV20 = param.asInt(); // assigning incoming value from pin V20 to a variable
  int pinValueV11 = param.asInt(); // assigning incoming value from pin V11 to a variable
  //Serial.print("V20 Slider value is: "); // to seral monitor
  Serial.print("V11 Slider value is: "); // to seral monitor
 //Serial.println(pinValueV20);
  if (pinValueV20 == 1 and pinValueV11 == 1  ) {
        //HIGH - ON
      Serial.println(F("Pin is HIGH")); // to seral monitor
       irsend.sendNEC(0xFB38C7,32); // ON
       
    }else {
       //LOW - OFF
    }
        
}

Where I’m wrong? Actually the code give the same feeback… if booth are ON or just one is high; the end clausole ins’t respected.

Thank you in advance for helping me

You just need to set a global variable and the use the BLYNK_WRITE functions to set the flag.

Im going assume that the PUSH mode widget will be the one you want to use to action the irsend.sendNEC(0xFB38C7,32);

bool pinValueV20;

BLYNK_WRITE(V20){ // SWITCH MODE
  if(param.asInt()){
    pinValueV20 = 1;
  } else {
    pinValueV20 = 0;
  }
}

BLYNK_WRITE(V21){ // PUSH MODE
 
  if(param.asInt() && pinValueV20){ // Check is pinValueV20 is HIGH, and also the PUSH button is held 
    irsend.sendNEC(0xFB38C7,32); // IR ON (obviously replace this with your own code)
  } else {
    irsend.sendNEC(0xFFFFFF,32); // IR OFF (obviously replace this with your own code)
  }
}

Hi Jamin,
thank you for your prompt feedback.
I updated the code as proposed by you and it works perfectly.

I added some high/low to be sure that TV button is active the other device are showed off.

//STATUS OTHER BUTTON MAIN MENU
    Blynk.virtualWrite(V12, LOW);
    Blynk.virtualWrite(V13, LOW);
    pinValueV11 = 1;
     } else {
    Blynk.virtualWrite(V11, LOW);  
    pinValueV11 = 0; 
  }

thank you again for your support. Task closed.

1 Like