#include <Wire.h>

const int MPU = 0x68;
float gyroX_raw, gyroY_raw, gyroZ_raw;
float gyroX, gyroY, gyroZ;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission (MPU);
  Wire.write (0x6B);
  Wire.write (0x00);
  Wire.endTransmission (true);

  Wire.beginTransmission (MPU);
  Wire.write (0x1B);
  Wire.write (0x08);  //Hexadecimal untuk bilangan biner 00001000
  Wire.endTransmission (true);

  delay (20);
}

void loop() {
  Wire.beginTransmission(MPU);
  Wire.write(0x43);
  Wire.endTransmission (false);
  Wire.requestFrom (MPU,6,true);

  gyroX_raw = Wire.read()<<8|Wire.read();
  gyroY_raw = Wire.read()<<8|Wire.read();
  gyroZ_raw = Wire.read()<<8|Wire.read();

  gyroX = gyroX_raw/65.5;
  gyroY = gyroY_raw/65.5;
  gyroZ = gyroZ_raw/65.5;

  Serial.print ("Kecepatan sudut = ");
  Serial.print (gyroX);
  Serial.println (" dps");
  Serial.print ("Kecepatan sudut = ");
  Serial.print (gyroY);
  Serial.println (" dps");
  Serial.print ("Kecepatan sudut = ");
  Serial.print (gyroZ);
  Serial.println (" dps");
  delay (500);
}