C language - Simultaneous button push & Switch

@T86157:

for this tid bit
int state = (buttonState << 1) | buttonState2;

wouldn't "&" be better in this case?

Each of the button variables can have a value of either zero or one.

Work it out with pencil and paper for all possible combinations of values (make a table).

Don't have a pencil? Don't have any paper? Heck, let the computer do it:

void setup()
{
    Serial.begin(9600);           
}

void loop()
{
    Serial.println("a   b   c");
    Serial.println("---------");

    for (int a = 0; a < 2; a++) {
        for (int b = 0; b < 2; b++) {
            int c = (a << 1) | b;
            Serial.print(a);
            Serial.print("   ");
            Serial.print(b);
            Serial.print("   ");
            Serial.println(c);
        }
    }
    Serial.println();
    delay(10000);
}

Output:


a   b   c
---------
0   0   0
0   1   1
1   0   2
1   1   3

Regards,

Dave