Disabling IoT switch

I am programming NodeMCU ESP32S on Arduino IoT cloud. Everything is ok.
I have two switches those are switch_1 and switch_2 .
I want make disable the switch_2 when i press the switch_1.
Is it possible?

Hi @auqaserdar. It is definitely possible. For example, you could do something like this in your Thing sketch:

/*
  Since switch_2 is READ_WRITE variable, onSwitch2Change() is
  executed every time a new value is received from IoT Cloud.
*/
void onSwitch2Change()  {
  if(switch_1 == true){
    // switch_1 is on, so don't do anything.
    return;
  }

  // Put your code here for reacting when switch_2 is changed while switch_1 is off.
}
1 Like

Yes, you can set a conditional statement in the code that detects a change in the state of switch_1 (for example, from not pressed to pressed), and then change the state of switch_2 to make it unavailable or vice versa.

1 Like