how to IF

Hey there! 8) thanks for your help i want to know how is the code to activate a pin if several pins are HIGH... EX. :grinning:

PINS 2, 3, 4, 5, INPUT PIN 8 OUTPUT

if pin 2, 3, 4, 5 are HIGH

then

pin 8 HIGH

else

Pin 8 LOW

THANKS!

http://arduino.cc/en/Reference/HomePage

Look under Boolean Operators. && means AND, || means OR. ! means NOT

So you could say something like:

if ((digitalRead(pin7) == HIGH) && (digitalRead(pin8) == HIGH) && (digitalRead(pin9) == HIGH))

You can use as many as you want. Be careful with your parenthesis though and think carefully about how you want it to work. But there's nothing you can't do with AND, OR, and NOT.

Read that part of the reference and you'll get it pretty quick.

Thanks ill try that :grin:

Couple of things ...

If the only test you ever need is to check that all 4 are pressed then just wire the switches in series and connect them to a single I/O pin

If you want to test several combinations of the 4 inputs it may be easier to assign a number to each (1,2,4, and 8 ) and add them up. For example if all are pressed you get 15. If 0 and 2 are pressed you get 1+4 = 5.

Then your tests reduce to something like if (pinTotal == 5) { etc

...R

thanks Robin2 your always helping me :D