Created
September 22, 2013 09:25
-
-
Save swarut/6658329 to your computer and use it in GitHub Desktop.
I2C connection example
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
#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