four switches, multiple outcome

Hello world!

I've ran into an interesting case that I cannot solve myself.
The general idea is that you have 4 switches. If you turn on each switch individualy, you get 4 different effects.
Now i would like to have a 5th option (and possibly even a 6th or 7th option) were 2 switches are turned on simultaniously. (eg. Switch1 and Switch2).

So far I've tried multiple setups and codes and the closest (and probably most n00b friendly) is the code displayed below:

  buttonState1 = digitalRead(Switch1);
  buttonState2 = digitalRead(Switch2);
  buttonState3 = digitalRead(Switch3);
  buttonState4 = digitalRead(Switch4);

if (digitalRead (Switch1) == HIGH && digitalRead (Switch2) == HIGH){
  buttonState5 == HIGH;
  }
else {
  buttonState5 == LOW; 
       }

But if I upload the code, it still activates the effect for each switch individualy (like I want it to), but whenever switch1 and switch2 are turned on simultaniously, it always runs only the effect of switch2 (wheter switch2 was turned on first or last).

Can somebody advise on how I could make this work?

Thanks in advance!

(P.S. I only posted the part where I ran into a problem, ofcourse all the appropriate pins are asigned)

(deleted)

If nothing is wrong with the rest of the code, or the wiring the sketch works.
Attach the entire code and the wiring diagram or send me a chrystal ball. My own one is out on a travel.

Or you could put all four switches in one value, giving you 16 combinations:

int buttonState = digitalRead(Switch1) * 8 +
                  digitalRead(Switch2) * 4 +
                  digitalRead(Switch3) * 2 +
                  digitalRead(Switch4);

switch (buttonState)
{
case 0:  // No switches

case 1: // Switch4 alone

case 2: // Switch3 alone

case 4: // Switch2 alone

case 8: // Switch1 alone

case 12:  // Switch1 & Switch2
}

johnwasser:
Or you could put all four switches in one value, giving you 16 combinations:

I was looking into the switchcase scenario but failed to make it work for my chase. I've applied what you said and now have the following code:

int buttonState = digitalRead(Switch1) * 8 +
                  digitalRead(Switch2) * 4 +
                  digitalRead(Switch3) * 2 +
                  digitalRead(Switch4);

switch (buttonState)
{

 case 0:  // No switches
 
  Left = LOW;
  Right = LOW;
  Warning = LOW;
  Police = LOW;
  Knight = LOW;
  LeftandRight = LOW;
 

case 1: // Switch1 alone

  Left = HIGH;
  Right = LOW;
  Warning = LOW;
  Police = LOW;
  Knight = LOW;
  LeftandRight = LOW;

case 2: // Switch2 alone
 
  Left = LOW;
  Right = HIGH;
  Warning = LOW;
  Police = LOW;
  Knight = LOW;
  LeftandRight = LOW;


case 3: // Switch3 alone
 
  Left = LOW;
  Right = LOW;
  Warning = HIGH;
  Police = LOW;
  Knight = LOW;
  LeftandRight = LOW;


case 4: // Switch4 alone 

  Left = LOW;
  Right = LOW;
  Warning = LOW;
  Police = HIGH;
  Knight = LOW;
  LeftandRight = LOW;

case 5:  // Switch1 & Switch2

  Left = LOW;
  Right = LOW;
  Warning = LOW;
  Police = LOW;
  Knight = LOW;
  LeftandRight = HIGH;
  
}

probably not the cleanest of codes... but I understand it.

When I applied your suggestion (thank you for that!) it goes directly to case 5 even no switches are activated and wont run the other cases. any advise on what I did wrong?

Smells an inadekvat definition of button inputs.....

Don't forget the break; following each case block...

lastchancename:
Don't forget the break; following each case block...

something small as that has made my code to work! thank you for pointing that out!
It still doesn't do exactly what i want it to do, but it is getting there :wink: I think I can work it out on my own now.

Thanks everybody for replying and contributing!

Goodbye world!

Don't miss the Karma[add] for the top guys!

Devinius:
something small as that has made my code to work! thank you for pointing that out!

Keep in mind that the break; is not required . In fact, there are times when you want the code to 'fall through' intentionally.