#include <MPU6050_tockn.h>
#include <Servo.h>
#include <Wire.h>
Servo ServoX;
Servo ServoY;
Servo ServoZ;
MPU6050 mpu6050(Wire);
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
ServoX.attach(3);
ServoY.attach(7);
ServoZ.attach(12);
}
void loop() {
mpu6050.update();
int eixoX = mpu6050.getAngleX();
int eixoY = mpu6050.getAngleY();
int eixoZ = mpu6050.getAngleZ();
float temp = mpu6050.getTemp();
int Xmapeado = map(eixoX, -90, 90, 0, 180);
int Ymapeado = map(eixoY, -90, 90, 0, 180);
int Zmapeado = map(eixoZ, -90, 90, 0, 180);
int restritoX = constrain(Xmapeado, 0, 180);
int restritoY = constrain(Ymapeado, 0, 180);
int restritoZ = constrain(Zmapeado, 0, 180);
ServoX.write(restritoX);
ServoY.write(restritoY);
ServoZ.write(restritoZ);
Serial.print("eixo X: " + String(restritoX) + "º\t");
Serial.print("eixo Y: " + String(restritoY) + "º\t");
Serial.print("eixo Z: " + String(restritoZ) + "º\t");
Serial.print("Temp.: " + String(temp,6) +" ºC\n");
}