reading switch states into an array

hi there

i am trying to read the state of 4 switches into an array to then use the value of this array to check agains a condition:

ideally, I want the states to be stored in a manner of:

my_switchstates[] = {0,1,0,1}

for the first and third switch being low and the second the fourth one being high.

i’m rather new to arduino - is that possible? if so, how do i check
the array in an if condition? is it simply:

if (my_switchstates[] == {0,1,0,1}) {
...
}

?

i’d be gracious for any help.
thanks,
#benni

For just four switches why don't you just use four byte variables? What is gained by using an array to hold the switch statuses?

Lefty

Well, you could do something like this:

if ((my_switchstates[0] | my_switchstates[1]<<1 | my_switchstates[2]<< 2 | my_switchstates[3]<< 3) == b0101) { blah(); }

That basically shifts the binary 1 that indicates each switch it set varying amounts to the left, then combines them into a single byte, which you can then compare with another byte to see if the bits that are set are the same. The b before the number on the right specfies it is in binary.

For just four switches why don't you just use four byte variables?

You see these youngsters are very wasteful. ;) For just four switches you only need one byte and that is giving you twice as much storage as you need.

Write to the byte with the bit set / clear commands http://www.arduino.cc/en/Reference/BitSet