Skip to content

Instantly share code, notes, and snippets.

@jackrobotics
Created November 28, 2018 10:48
Show Gist options
  • Save jackrobotics/9de5412d1e77a3e5e7cd332244a24a96 to your computer and use it in GitHub Desktop.
Save jackrobotics/9de5412d1e77a3e5e7cd332244a24a96 to your computer and use it in GitHub Desktop.
/*
* By JackRoboticS
* www.jackrobotics.me
*/
#include <Wire.h>
byte ADDRESS_PCF8574 = 0B0100000 | 0B000; //address 000
//byte ADDRESS_PCF8574 = 0B0100000 | 0B001; //address 001
//byte ADDRESS_PCF8574 = 0B0100000 | 0B010; //address 010
//byte ADDRESS_PCF8574 = 0B0100000 | 0B011; //address 011
//byte ADDRESS_PCF8574 = 0B0100000 | 0B100; //address 100
//byte ADDRESS_PCF8574 = 0B0100000 | 0B101; //address 101
//byte ADDRESS_PCF8574 = 0B0100000 | 0B110; //address 110
//byte ADDRESS_PCF8574 = 0B0100000 | 0B111; //address 111
void setup() {
Wire.begin();
}
void busWrite(byte addr,byte io){
Wire.beginTransmission(addr); // begin transmission and set address
Wire.write(io); // send data io
Wire.endTransmission(); // end transmission
}
byte busRead(byte addr){
byte io = 0x00;
Wire.requestFrom(addr, 1); // request data from address
if (Wire.available()) {
io = Wire.read(); // read data io
}
return io;
}
void loop() {
// byte io = busRead(ADDRESS_PCF8574);
busWrite(ADDRESS_PCF8574,0B00000000);
delay(1000);
busWrite(ADDRESS_PCF8574,0B11111111);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment