[SOLVED] Toggling between two commands

Dear Sirs,
I am trying to implement something and I have stucked at a very silly point.
What i want? Using a virtual pin as switch in push mode, I want the first time that I push the Blynk virtual button (switch) my ESP application to execute command 1, the second time to execute command 2… in short to toggle between command 1 and command 2…
How??? I burned my head to solve this simple problem…

Thanks and Best Regards,
Mike Kranidis

The shorthand for “toggling” is something like:

yourvariable = !yourvariable;


if (yourvariable == 1){
  yourvariable = 0;
  //do something
  yourvariable = 1;
  // do something different

Hello @Costas!

I am using BLYNK_WRITE(V1)
Pseudo Code:
if (param.asInt() )
execute command 1;
else if (param.asInt() )
execute command 2;

I know that from my pseudo code is missing the logic to implement the toggling of the commands but that is my problem…


why this is does not work???

status is a boolen global value initially has LOW

    if (param.asInt() && status == LOW) {
    command 1;
    status = HIGH;
    } else {
    command 2;
    status = LOW;

i found my bug, it was the double == instead of single = I corrected my code above


bool / boolean is true or false not LOW.

1 Like

yes @Costas your suggestion solve my problem. Thanks!