Tv Status on virtual pin

Hi guys, I’m trying to save the Tv status (on or off) so I can only turn off when it is on (does it make sense?)


BLYNK_WRITE(V16){
    //TV on/off
    //irsend.sendNEC(0xFDC03F, 32);
    if(flag == 0 && param.asInt() == 1){
    irsend.sendNEC(0xFDC03F, 32);
    Blynk.virtualWrite(V20, "TV Ligada");
    flag = 1;
}    
    if(param.asInt() == 1 && flag == 1){
    irsend.sendNEC(0xFDC03F, 32);
    Blynk.virtualWrite(V20, "TV Desligada");
    flag = 0;
}


this is the code that I am using, but what happens is that V20 aways show “TV desligada”

You’re processing the first ‘if’ statement, then setting conditions that will make the second ‘if’ statement true, so that is being processed as well.

Making the second one an ‘else if’ instead should do the trick (I think)…

Pete.

1 Like

Worked!! thank very much

1 Like

You’re welcome. I’ve changed the status to ‘Solved’.

Pete.