This code flashes each LED in turn and then leaves it in the inverse state.
/*
PCF adress = 0x38
configured as output to control the relay
*/
#define PCF2_output 0x38 // (Relay) PCF8574AN, Address 0x38 with A0-A1-A2 pins grounded.
#include <Wire.h>
byte dat = 0xff;
void setup()
{
Wire.begin();
Serial.begin(9600);
outputData(dat); // all outputs high
}
void loop()
{
// pin 0 toggling
for(int i=0;i<5;i++){
dat ^= 0x1; // toggle output 0
outputData(dat);
delay(200);
}
// pin 0 toggling
for(int i=0;i<5;i++){
dat ^= 0x2; // toggle output 1
outputData(dat);
delay(200);
}
// pin 0 toggling
for(int i=0;i<5;i++){
dat ^= 0x4; // toggle output 2
outputData(dat);
delay(200);
}
}
void outputData(byte dat){
Wire.beginTransmission(PCF2_output);
Wire.write(dat); // turn relay 3 on (P2)
Wire.endTransmission();
}