#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
int16_t ax, ay, az;
int16_t gx, gy, gz;
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
while (!mpu.begin()) {
Serial.println("MPU6050 not connected!");
delay(1000);
}
Serial.println("MPU6050 ready!");
}
sensors_event_t event;
void loop() {
mpu.getAccelerometerSensor()->getEvent(&event);
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
acceleration.x = map(ax, -17000, 17000, 0, 179);
acceleration.y = map(ay, -17000, 17000, 0, 179);
acceleration.z = map(az, -17000, 17000, 0, 179);
Serial.print("[");
Serial.print(millis());
Serial.print("] X: ");
Serial.print(event.acceleration.x);
Serial.print(", Y: ");
Serial.print(event.acceleration.y);
Serial.print(", Z: ");
Serial.print(event.acceleration.z);
Serial.println(" m/s^2");
delay(500);
}