# include "Wire.h"
# include "I2Cdev.h"
# include "MPU6050.h"
# include <Servo.h>
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
Servo servo1;
Servo servo2;
int val1;
int val2;
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(115200);
Serial.print("Initialize MPU");
mpu.initialize();
Serial.println(mpu.testConnection() ? "connected" : "connection failed");
servo1.attach(2);
servo2.attach(3);
}
void loop() {
// put your main code here, to run repeatedly:
mpu.getMotion6(&ax,&ay,&az,&gx,&gy,&gz);
val1 = map(gx, -17000, 17000, 0, 179);
servo1.write(val1);
val2 = map(gy, -17000, 17000, 0, 179);
servo2.write(val2);
}