Created
August 7, 2012 04:11
-
-
Save brooksware2000/3281472 to your computer and use it in GitHub Desktop.
PCF8574A I2C I/O routine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/****************************************************************************** | |
* 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