Code:
#include "Arduino.h"
#include "PCF8574.h"
TwoWire I2Ctwo = TwoWire(1);
// Set i2c address
PCF8574 pcf8574_R1(&I2Ctwo, 0x24, 15, 13);
PCF8574 pcf8574_R2(&I2Ctwo, 0x25, 15, 13);
PCF8574 pcf8574_R3(&I2Ctwo, 0x21, 15, 13);
PCF8574 pcf8574_R4(&I2Ctwo, 0x22, 15, 13);
void setup()
{
Serial.begin(115200);
// delay(1000);
// Set pinMode to OUTPUT
pcf8574_R1.pinMode(P0, OUTPUT);
pcf8574_R1.pinMode(P1, OUTPUT);
pcf8574_R1.pinMode(P2, OUTPUT);
pcf8574_R1.pinMode(P3, OUTPUT);
pcf8574_R1.pinMode(P4, OUTPUT);
pcf8574_R1.pinMode(P5, OUTPUT);
pcf8574_R1.pinMode(P6, OUTPUT);
pcf8574_R1.pinMode(P7, OUTPUT);
pcf8574_R2.pinMode(P0, OUTPUT);
pcf8574_R2.pinMode(P1, OUTPUT);
pcf8574_R2.pinMode(P2, OUTPUT);
pcf8574_R2.pinMode(P3, OUTPUT);
pcf8574_R2.pinMode(P4, OUTPUT);
pcf8574_R2.pinMode(P5, OUTPUT);
pcf8574_R2.pinMode(P6, OUTPUT);
pcf8574_R2.pinMode(P7, OUTPUT);
pcf8574_R3.pinMode(P0, OUTPUT);
pcf8574_R3.pinMode(P1, OUTPUT);
pcf8574_R3.pinMode(P2, OUTPUT);
pcf8574_R3.pinMode(P3, OUTPUT);
pcf8574_R3.pinMode(P4, OUTPUT);
pcf8574_R3.pinMode(P5, OUTPUT);
pcf8574_R3.pinMode(P6, OUTPUT);
pcf8574_R3.pinMode(P7, OUTPUT);
pcf8574_R4.pinMode(P0, OUTPUT);
pcf8574_R4.pinMode(P1, OUTPUT);
pcf8574_R4.pinMode(P2, OUTPUT);
pcf8574_R4.pinMode(P3, OUTPUT);
pcf8574_R4.pinMode(P4, OUTPUT);
pcf8574_R4.pinMode(P5, OUTPUT);
pcf8574_R4.pinMode(P6, OUTPUT);
pcf8574_R4.pinMode(P7, OUTPUT);
Serial.print("Init pcf8574_R1...");
if (pcf8574_R1.begin()){
Serial.println("PCF8574_R1_OK");
}else{
Serial.println("PCF8574_R1_KO");
}
Serial.print("Init pcf8574_R2...");
if (pcf8574_R2.begin()){
Serial.println("PCF8574_R2_OK");
}else{
Serial.println("PCF8574_R2_KO");
}
Serial.print("Init pcf8574_R3...");
if (pcf8574_R3.begin()){
Serial.println("PCF8574_R3_OK");
}else{
Serial.println("PCF8574_R3_KO");
}
Serial.print("Init pcf8574_R4...");
if (pcf8574_R4.begin()){
Serial.println("PCF8574_R4_OK");
}else{
Serial.println("PCF8574_R4_KO");
}
}
void loop()
{
pcf8574_R1.digitalWrite(P0, LOW);
delay(200);
pcf8574_R1.digitalWrite(P1, LOW);
delay(200);
pcf8574_R1.digitalWrite(P2, LOW);
delay(200);
pcf8574_R1.digitalWrite(P3, LOW);
delay(200);
pcf8574_R1.digitalWrite(P4, LOW);
delay(200);
pcf8574_R1.digitalWrite(P5, LOW);
delay(200);
pcf8574_R1.digitalWrite(P6, LOW);
delay(200);
pcf8574_R1.digitalWrite(P7, LOW);
delay(200);
pcf8574_R2.digitalWrite(P0, LOW);
delay(200);
pcf8574_R2.digitalWrite(P1, LOW);
delay(200);
pcf8574_R2.digitalWrite(P2, LOW);
delay(200);
pcf8574_R2.digitalWrite(P3, LOW);
delay(200);
pcf8574_R2.digitalWrite(P4, LOW);
delay(200);
pcf8574_R2.digitalWrite(P5, LOW);
delay(200);
pcf8574_R2.digitalWrite(P6, LOW);
delay(200);
pcf8574_R2.digitalWrite(P7, LOW);
delay(200);
pcf8574_R3.digitalWrite(P0, LOW);
delay(200);
pcf8574_R3.digitalWrite(P1, LOW);
delay(200);
pcf8574_R3.digitalWrite(P2, LOW);
delay(200);
pcf8574_R3.digitalWrite(P3, LOW);
delay(200);
pcf8574_R3.digitalWrite(P4, LOW);
delay(200);
pcf8574_R3.digitalWrite(P5, LOW);
delay(200);
pcf8574_R3.digitalWrite(P6, LOW);
delay(200);
pcf8574_R3.digitalWrite(P7, LOW);
delay(200);
pcf8574_R4.digitalWrite(P0, LOW);
delay(200);
pcf8574_R4.digitalWrite(P1, LOW);
delay(200);
pcf8574_R4.digitalWrite(P2, LOW);
delay(200);
pcf8574_R4.digitalWrite(P3, LOW);
delay(200);
pcf8574_R4.digitalWrite(P4, LOW);
delay(200);
pcf8574_R4.digitalWrite(P5, LOW);
delay(200);
pcf8574_R4.digitalWrite(P6, LOW);
delay(200);
pcf8574_R4.digitalWrite(P7, LOW);
delay(200);
}