Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PCF8574A I2C I/O routine
/******************************************************************************
* PCF8574A I2C Output
*
* Prototype I2C interface to PCF8574A I/O Expander.
*
* Arduino analog input 5 - I2C SCL
* Arduino analog input 4 - I2C SDA
*
******************************************************************************/
// Up to 8 devices can share the same I2C bus starting from address 38h to 3Fh
// hexadecimal (56 to 63 decimal)
#define DEVICE_ADDRESS 56
#include <Wire.h>
void setup()
{
Wire.begin(); // Join I2C bus
deviceWrite(B11111111); // Set all LEDs off
}
void loop()
{
deviceWrite(B11111001); // Turn on LEDs connected to P1 and P2
// Turn off LED connected to P0
delay(1000); // Delay 1 second
deviceWrite(B11111110); // Turn off LEDs connected to P1 and P2
// Turn on LED connected to P0
delay(1000); // Delay 1 second
}
void deviceWrite(byte txData)
{
Wire.beginTransmission(DEVICE_ADDRESS);
Wire.send(txData);
Wire.endTransmission();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment