Skip to content

Instantly share code, notes, and snippets.

@swarut
Created September 22, 2013 09:25
Show Gist options
  • Save swarut/6658329 to your computer and use it in GitHub Desktop.
Save swarut/6658329 to your computer and use it in GitHub Desktop.
I2C connection example
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
}
int reading = 0;
void loop() {
if (Serial.available() > 0) {
int input = Serial.read();
Serial.write("read :");
Serial.write(input);
Serial.write("\n");
command(input);
}
delay(70);
}
void off(void){
// 32 = 0x20 --> this is the first address of PCF8574. it should be changed when you changed the chip.
Wire.beginTransmission(32);
Wire.write(byte(0x00));
Wire.endTransmission();
}
void on(void){
// 32 = 0x20 --> this is the first address of PCF8574. it should be changed when you changed the chip.
Wire.beginTransmission(32);
Wire.write(byte(0xFF));
Wire.endTransmission();
}
void command(int cmd) {
Wire.beginTransmission(32);
Wire.write(byte(cmd));
Wire.endTransmission();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment