Code:
#include "Arduino.h"
#include "PCF8574.h"
#define A4S_SDA 4
#define A4S_SCL 16
TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);
PCF8574 pcf8574_RE1(&I2Cone,0x24,A4S_SDA,A4S_SCL);//DO
/*PCF8574 pcf8574_RE2(&I2Cone,0x21,A4S_SDA,A4S_SCL);//DO
PCF8574 pcf8574_IN1(&I2Ctwo,0x22,A4S_SDA,A4S_SCL);//DI
PCF8574 pcf8574_IN2(&I2Ctwo,0x24,A4S_SDA,A4S_SCL);//DI*/
void setup()
{
Serial.begin(115200);
pcf8574_RE1.pinMode(P0, OUTPUT);
pcf8574_RE1.pinMode(P1, OUTPUT);
pcf8574_RE1.pinMode(P2, OUTPUT);
pcf8574_RE1.pinMode(P3, OUTPUT);
pcf8574_RE1.pinMode(P4, INPUT);
pcf8574_RE1.pinMode(P5, INPUT);
pcf8574_RE1.pinMode(P6, INPUT);
pcf8574_RE1.pinMode(P7, INPUT);
pcf8574_RE1.begin();
}
void loop()
{
/* pcf8574_RE1.digitalWrite(P0, HIGH);delay(1000);
pcf8574_RE1.digitalWrite(P1, HIGH);delay(1000);
pcf8574_RE1.digitalWrite(P2, HIGH);delay(1000);
pcf8574_RE1.digitalWrite(P3, HIGH);delay(1000);
pcf8574_RE1.digitalWrite(P0, LOW);delay(1000);
pcf8574_RE1.digitalWrite(P1, LOW);delay(1000);
pcf8574_RE1.digitalWrite(P2, LOW);delay(1000);
pcf8574_RE1.digitalWrite(P3, LOW);delay(1000);*/
if(pcf8574_RE1.digitalRead(P4)==LOW)
{
Serial.println("D09 PRESSED");
pcf8574_RE1.digitalWrite(P0, LOW);
}else pcf8574_RE1.digitalWrite(P0, HIGH);
delay (100);
if(pcf8574_RE1.digitalRead(P5)==LOW)
{
Serial.println("D10 PRESSED");
pcf8574_RE1.digitalWrite(P1, LOW);
}else pcf8574_RE1.digitalWrite(P1, HIGH);
delay (100);
if(pcf8574_RE1.digitalRead(P6)==LOW)
{
Serial.println("D11 PRESSED");
pcf8574_RE1.digitalWrite(P2, LOW);
}else pcf8574_RE1.digitalWrite(P2, HIGH);
delay (100);
if(pcf8574_RE1.digitalRead(P7)==LOW)
{
Serial.println("D12 PRESSED");
pcf8574_RE1.digitalWrite(P3, LOW);
}else pcf8574_RE1.digitalWrite(P3, HIGH);
delay (100);
delay(20);
}