#include <MPU6050.h>
#include <ESP32Servo.h>
#include <Wire.h>
#define MPU6050_I2C_ADDRESS 0x68
#define SERVO_PIN 2
MPU6050 mpu6050;
Servo servo;
int16_t gyroX, gyroY, gyroZ;
void setup() {
Wire.begin();
Serial.begin(9600);
servo.attach(SERVO_PIN);
mpu6050.initialize();
}
void loop() {
mpu6050.getRotation(&gyroX, &gyroY, &gyroZ);
int servoAngle1 = map(gyroX, 0, 32767, 0,180);
servo.write(servoAngle1);
delay(20);
}