I am working with a PCA9555 i/o expander and need to be able to switch outputs on and off at times without affecting existing outputs current state
Here is the portion of the code that is currently being used to turn on a single pin:
#include <Wire.h>
#define PCA9555 0x22 // 0x22 is address for PCA9555
#define IN_P0 0x00 // Read Input port0
#define IN_P1 0x01 // Read Input port1
#define OUT_P0 0x02 // Write Output port0
#define OUT_P1 0x03 // Write Output port1
#define CONFIG_P0 0x06 // Configuration port0 configures the direction of the I/O pins 0 is output 1 is input
#define CONFIG_P1 0x07 // Configuration port1 configures the direction of the I/O pins 0 is output 1 is input
//=======================================================
// Initialize
//=======================================================
void setup() {
Serial.begin(9600); // start serial comms for Debug 9600 baud
Wire.begin(PCA9555); // join i2c bus (address optional for master) tried to get working
write_io (CONFIG_P0, B00000000); //defines all pins on Port0 are outputs
write_io (CONFIG_P1, B00000000); //defines all pins on Port1 are outputs
write_io (OUT_P0, B00000000); //clears all outputs
write_io (OUT_P1, B00000000); //clears all outputs
delay(1000); //
write_io (OUT_P1, B00000010);
}
void loop(){
}
void write_io(int command, int value){ //PCA9555 command processor
Wire.beginTransmission(PCA9555);
Wire.write(command),Wire.write(value);
Wire.endTransmission();
}
So as you can see at this stage I am just turning on one output on the PCA9555.
I am wondering how to “mask” the command so that ONLY the pins I want to change, change when I need to switch other outputs on this chip without affecting the others!
i.e.I am unsure on how to apply a bitmask to my command to say change the output of say P10 of the PCA9555 without affecting the status of P11
Can someone point me in the right direction?