#include<Wire.h>
const int MPU_addr=0x68; // I2C address of the MPU-6050
short xgyro, xacc, yacc;
short mpu_read(short reg_addr);
void setup(){
Wire.begin();
Serial.begin(9600);
}
void loop(){
yacc = mpu_read(0x3B);
xacc = mpu_read(0x43);
xgyro = mpu_read(0x3D);
Serial.print("pos : ") & Serial.print(xacc) & Serial.print(" | ") & Serial.println(yacc);
Serial.print("dir : ") & Serial.println(xgyro);
delay(1000);
}
short mpu_read(short reg_addr){
Wire.beginTransmission(MPU_addr);
Wire.requestFrom(MPU_addr, 2, true);
Wire.write(reg_addr);
short output = Wire.read() << 8 | Wire.read();
Wire.endTransmission(true);
return output;
}