//---------------------------------I2C Events-------------------------------// void receiveEvent(int bytesReceived){ int i=0; clearReceiveBuffer(); while(Wire.available()){ receiveBuffer[i++] = Wire.read(); } } void requestEvent(){ int memoryAddress = receiveBuffer[0]; if (memoryAddress >= ARD_DATA )//&& memoryAddress <=ARD_DATA + NUM_OF_SENSORS) { uint8_t data[8]; // each sensor is 2 byte value char dir=0; if(X<0) {dir|=0x01;xdata=abs(X);}else xdata=X; // dir&0x01==1 is mean X<0 else X>0 if(Y<0) {dir|=0x02;ydata=abs(Y);}else ydata=Y; // dir&0x02==1 is mean Y<0 else Y>0 if(W<0) {dir|=0x04;wdata=abs(W);}else wdata=W; // dir&0x04==1 is mean W<0 else W>0 data[0]=highByte(dir); //data[0] and data[1] to Determine the negative or positive value of X,Y,W. data[1]=lowByte(dir); data[2]=highByte(xdata);//data[2] and data[3] absolute value of X axis data[3]=lowByte(xdata); data[4]=highByte(ydata); data[4] and data[5] absolute value of Y axis data[5]=lowByte(ydata); data[6]=highByte(wdata); data[7]=lowByte(wdata); data[6] and data[7] absolute value of Wheel int startidx = memoryAddress-ARD_DATA; Wire.write(data+startidx,8); //Send to end of buffer } }