Guest User

Untitled

a guest
Dec 21st, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <Wire.h>
  2. #define BUFFER_SIZE (192)
  3.  
  4. unsigned char buf[BUFFER_SIZE];
  5.  
  6. void setup()
  7. {
  8.   Wire.begin(4);                // join i2c bus with address #4
  9.   Wire.onReceive(receiveEvent); // register event
  10. }
  11.  
  12. void loop()
  13. {
  14.   //Do whatever you need to with buf in here.
  15.   delay(100);
  16. }
  17.  
  18. // function that executes whenever data is received from master
  19. // this function is registered as an event, see setup()
  20. void receiveEvent(int howMany)
  21. {
  22.   unsigned char i = 0;
  23.   while(Wire.available() && (i < BUFFER_SIZE))
  24.   {
  25.     buf[i++] = Wire.read(); // receive byte
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment