Button issue in the code

Hi, I'm having a small issue with the buttons. I have 2 buttons in the code. One turns the LED on while the other tunrs the LED off. Those 2 work fine. Now I had the idea of adding 2 more buttons. Now that kind of works good as well except if you don't click on "led off" before clicking on the first button. For example: I click on button1 "led1 on" the led goes on. I click on button2 "led1 off" the led goes off. But if I click on button1 "led1 on" the led goes on and then I click on button3 "led3 on" led1 goes off just fine but the other led3 with button3 goes on immediately. Now starts the problem. Now if I click on button2 "led1 off" it does something. Like turning led2 on or sometimes does nothing. Goes all haywire. If I click then on button1 "led1 on" it doesn't respond anymore. I then have to click on button4 to turn this led3 off. Ohterwise button1 "led1 on" and button3 "led3 on" will only toggle back and forth. but nothing will really be turned off. How can I prevent a button from functioning when one button is pressed. For instance. When button1 "led1 on" is clicked - no other button should function when clicked (basically not taking any input) - except button2 "led1 off" - only then should button 3 "led3 on" function again. Can someone help me to make this happen? Thank you so much in advance.

Kind of hard to help you without your code.

Or how the switches are wired.

Newbie88: When button1 "led1 on" is clicked - no other button should function when clicked (basically not taking any input) - except button2 "led1 off" - only then should button 3 "led3 on" function again.

Consider the following pseudo code:

void loop()
{
   if (button1 is clicked && button2Status is not ON) {
      button1Status = ON;
   }
   if (button2 is clicked) {
      button1Status = OFF;
   }

   if (button3 is clicked && button1Status is not ON) {
      button2Status = ON;
   }
   if (button4 is clicked) {
      button2Status = OFF;
   }

   digitalWrite(led1, button1Status);
   digitalWrite(led2, button2Status);
}

Hi,
What are the two EXTRA buttons supposed to do?

Can you post your complete code?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks… Tom… :slight_smile:

Hi ya all, thx for the quick reply…thx Karma74, your suggestion put me on the right track. I then actually used a counter. Set the counter to “0” in the set up-then for each button press I changed the counter to a different number-only at the stop button when it is pushed did I set the counter back to “0”-so only if the counter is “0” will the other buttons work or respond to the push…so now I have only 3 buttons-one on PIN1 and one button on PIN2-and only one stop button to set both PINs to LOW and the counter back to “0”…now if I press on one button it gives the counter a differnt number then “0”…therefore no other button will respond except the stop button…
if (request.indexOf("/blue") != -1 && counter==0)
counter = 1;
digitalWrite(wifiPin2, HIGH);
digitalWrite(wifiPin1, LOW);
value = HIGH;
Only for the stop button did I set the counter back to “0”
That’s how I wanted it.
Thx ya all and a happy new year

Almost none of reply #5 makes any sense to me and you still have not posted your whole program

In this program snippet

if (request.indexOf("/blue") != -1 && counter==0)
counter = 1;
digitalWrite(wifiPin2, HIGH);
digitalWrite(wifiPin1, LOW);
value = HIGH;

Which program statements are dependent on the result of the test and which will be executed unconditionally no matter what the result of the test ?