How to set PCF8574 using 8 variables


I use
to set the PCF8574 pins.

But now I have to do it using 8 variables, or an array.

My varables:
How should I do that?

Build up the variables into the byte to send using the bitwise OR and shifts If you variables only contain 0 or 1 you can use:-

byteToSend = P1 | (P2 <<1) | (P3 << 2) | (P4 << 3) … and so on