Created
October 6, 2012 06:39
-
-
Save biskandar/3844237 to your computer and use it in GitHub Desktop.
Using I2C as Communication Link between Arduinos 2012010402
This file contains hidden or 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() { | |
Serial.begin( 9600 ) ; | |
while ( !Serial ) ; | |
// run as I2C Slave with id = 1 | |
int slaveId = 1 ; | |
Wire.begin( slaveId ) ; | |
// setup callback function | |
Wire.onReceive( onWireReceive ) ; | |
} | |
void loop() { | |
// nothing to do | |
} | |
void onWireReceive( int howMany ) { | |
while ( Wire.available() ) { | |
// print back all the characters | |
// into console terminal | |
char ch = Wire.read() ; | |
Serial.print( ch ) ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment