Skip to content

Instantly share code, notes, and snippets.

@jackrobotics
Created November 28, 2018 10:55
Show Gist options
  • Save jackrobotics/5b1d204ac2f1567aa874c769b819dfda to your computer and use it in GitHub Desktop.
Save jackrobotics/5b1d204ac2f1567aa874c769b819dfda to your computer and use it in GitHub Desktop.
/*
* By JackRoboticS
* www.jackrobotics.me
*/
#include "Wire.h"
TwoWire WIRE(0);
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(21,22);
WIRE.setClock(100000L);
}
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