// I2C PCF8574 8 bit i/o port expander // by AEP // // testing / prototyping the Wire library in combination with the ic PCF8574 // Reads data from PCF8574 over I2C and sends data to another PCF8574 over the same I2C bus // Created 21 oct 2012 #include byte iInput=0; byte iOutput=0; void setup() { Wire.begin(); } void loop() { Wire.requestFrom(33,1);// Begin transmission to PCF8574 with the buttons if(Wire.available()) // If bytes are available to be recieved { iInput = Wire.read();// Read a byte } if(iInput<255) //If the value less than 255 { if (iInput==254) // P0 { iOutput = 1; }; if (iInput==253) // P1 { iOutput = 2; }; if (iInput==251) // P2 { iOutput = 4; }; if (iInput==247) // P3 { iOutput = 8; }; } Wire.beginTransmission(32); //Begin transmission to PCF8574 (with the LEDs) Wire.write(iOutput); //Send data to PCF8574 (with the LEDs) Wire.endTransmission(); //End Transmission to PCF8574 (with the LEDs) }