Code:
/*KC868-E16S Code of PCF8574 OUTPUT CONTROL RELAYS*/
/*Press and hold on key Download ,relays ON, release key relays OFF*/
#include "Arduino.h"
#include "PCF8574.h"
/*Set pcf8574 Output i2c address and SDA IO16/ SCL IO15*/
#define buttonPin 0
PCF8574 pcf8574_1(0x21,16,15);
PCF8574 pcf8574_2(0x25,16,15);
void setup()
{
Serial.begin(115200);
/* Set pinMode to OUTPUT*/
pinMode(buttonPin, INPUT);// key download IO0
pcf8574_1.pinMode(P0, OUTPUT);
pcf8574_1.pinMode(P1, OUTPUT);
pcf8574_1.pinMode(P2, OUTPUT);
pcf8574_1.pinMode(P3, OUTPUT);
pcf8574_1.pinMode(P4, OUTPUT);
pcf8574_1.pinMode(P5, OUTPUT);
pcf8574_1.pinMode(P6, OUTPUT);
pcf8574_1.pinMode(P7, OUTPUT);
pcf8574_2.pinMode(P0, OUTPUT);
pcf8574_2.pinMode(P1, OUTPUT);
pcf8574_2.pinMode(P2, OUTPUT);
pcf8574_2.pinMode(P3, OUTPUT);
pcf8574_2.pinMode(P4, OUTPUT);
pcf8574_2.pinMode(P5, OUTPUT);
pcf8574_2.pinMode(P6, OUTPUT);
pcf8574_2.pinMode(P7, OUTPUT);
pcf8574_1.begin();
pcf8574_2.begin();
}
void loop()
{
if(digitalRead(buttonPin)==0)
{
pcf8574_1.digitalWrite(P0, LOW); delay(100);
pcf8574_1.digitalWrite(P1, LOW); delay(100);
pcf8574_1.digitalWrite(P2, LOW); delay(100);
pcf8574_1.digitalWrite(P3, LOW); delay(100);
pcf8574_1.digitalWrite(P4, LOW); delay(100);
pcf8574_1.digitalWrite(P5, LOW); delay(100);
pcf8574_1.digitalWrite(P6, LOW); delay(100);
pcf8574_1.digitalWrite(P7, LOW); delay(100);
pcf8574_2.digitalWrite(P0, LOW); delay(100);
pcf8574_2.digitalWrite(P1, LOW); delay(100);
pcf8574_2.digitalWrite(P2, LOW); delay(100);
pcf8574_2.digitalWrite(P3, LOW); delay(100);
pcf8574_2.digitalWrite(P4, LOW); delay(100);
pcf8574_2.digitalWrite(P5, LOW); delay(100);
pcf8574_2.digitalWrite(P6, LOW); delay(100);
pcf8574_2.digitalWrite(P7, LOW); delay(100);
}
else
{
pcf8574_1.digitalWrite(P0, HIGH); delay(100);
pcf8574_1.digitalWrite(P1, HIGH); delay(100);
pcf8574_1.digitalWrite(P2, HIGH); delay(100);
pcf8574_1.digitalWrite(P3, HIGH); delay(100);
pcf8574_1.digitalWrite(P4, HIGH); delay(100);
pcf8574_1.digitalWrite(P5, HIGH); delay(100);
pcf8574_1.digitalWrite(P6, HIGH); delay(100);
pcf8574_1.digitalWrite(P7, HIGH); delay(100);
pcf8574_2.digitalWrite(P0, HIGH); delay(100);
pcf8574_2.digitalWrite(P1, HIGH); delay(100);
pcf8574_2.digitalWrite(P2, HIGH); delay(100);
pcf8574_2.digitalWrite(P3, HIGH); delay(100);
pcf8574_2.digitalWrite(P4, HIGH); delay(100);
pcf8574_2.digitalWrite(P5, HIGH); delay(100);
pcf8574_2.digitalWrite(P6, HIGH); delay(100);
pcf8574_2.digitalWrite(P7, HIGH); delay(100);
}
}