#include <Wire.h>
#include <MPU6050.h>
#include <Servo.h>
Servo ss;
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
void setup() {
Serial.begin(9600);
Serial.println("Initialize MPU");
mpu.initialize();
ss.attach(6);
}
void loop() {
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// Map the accelerometer data from all three axes to a suitable range for servo control
int valX = map(ax, -17000, 17000, 0, 180);
int valY = map(ay, -17000, 17000, 0, 180);
int valZ = map(az, -17000, 17000, 0, 180);
// Set the servo position based on the mapped values from each axis
ss.write(valX);
// Print the mapped values of each axis to the serial monitor
Serial.print("Mapped value - X axis: ");
Serial.println(valX);
Serial.print("Mapped value - Y axis: ");
Serial.println(valY);
Serial.print("Mapped value - Z axis: ");
Serial.println(valZ);
delay(2000);
}