#include <LiquidCrystal_I2C.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(8, 1);
lcd.print("AXEL");
lcd.setCursor(0, 3);
lcd.print("By: Arkan Asadil H");
delay(500);
lcd.clear();
while (!mpu.begin()) {
lcd.setCursor(0, 0);
lcd.print("MPU6050 not ready!");
lcd.setCursor(0, 1);
lcd.print(millis()/1000);
lcd.print(" Sec");
delay(1000);
}
mpu.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu.setGyroRange(MPU6050_RANGE_250_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
lcd.println("MPU6050 ready!");
delay(100);
lcd.clear();
}
sensors_event_t event;
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
lcd.setCursor(0, 0);
lcd.print("X:");
lcd.print(a.acceleration.x);
lcd.print(" R:");
lcd.println(g.gyro.x);
lcd.setCursor(0, 1);
lcd.print("Y:");
lcd.print(a.acceleration.y);
lcd.print(" P:");
lcd.println(g.gyro.y);
lcd.setCursor(0, 2);
lcd.print("Z:");
lcd.print(a.acceleration.z);
lcd.print(" Y:");
lcd.println(g.gyro.z);
lcd.setCursor(0, 3);
lcd.print(millis() % 1000);
lcd.print(" millis");
lcd.print(" T:");
lcd.println(temp.temperature);
delay(1);
}