Papermind

slave

Dec 29th, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <Wire.h>
  2. void setup() {
  3.   Wire.begin(8);                // join i2c bus with address #8
  4.   Wire.onReceive(receiveEvent); // register event
  5.   Serial.begin(9600);           // start serial for output
  6. }
  7. void loop() {
  8.   delay(100);}
  9. // function that executes whenever data is received from master
  10. // this function is registered as an event, see setup()
  11.  
  12. void receiveEvent(int howMany) {
  13. while (1 < Wire.available()) { // loop through all but the last
  14. char c = Wire.read(); // receive byte as a character
  15. Serial.print(c);         // print the character
  16.   }
  17.   int x = Wire.read();    // receive byte as an integer
  18.   Serial.println(x);         // print the integer
  19. }
Advertisement
Add Comment
Please, Sign In to add comment