Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #define BUFFER_SIZE (192)
- unsigned char buf[BUFFER_SIZE];
- void setup()
- {
- Wire.begin(4); // join i2c bus with address #4
- Wire.onReceive(receiveEvent); // register event
- }
- void loop()
- {
- //Do whatever you need to with buf in here.
- delay(100);
- }
- // function that executes whenever data is received from master
- // this function is registered as an event, see setup()
- void receiveEvent(int howMany)
- {
- unsigned char i = 0;
- while(Wire.available() && (i < BUFFER_SIZE))
- {
- buf[i++] = Wire.read(); // receive byte
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment