#include <Wire.h>
#include <LiquidCrystal.h>
#include <MPU6050.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
MPU6050 mpu;
void setup() {
lcd.begin(16, 2);
Wire.begin();
mpu.initialize();
}
void loop() {
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
float angle_x = atan2(ay, az) * 180.0 / PI; // Calculate angle in degrees around x-axis
float angle_y = atan2(ax, az) * 180.0 / PI; // Calculate angle in degrees around y-axis
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("X: ");
lcd.print(angle_x);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("Y: ");
lcd.print(angle_y);
lcd.print(" ");
int16_t x_pos = map(angle_x, -90, 90, 0, 16); // Map angle to screen coordinates
int16_t y_pos = map(angle_y, -90, 90, 0, 16); // Map angle to screen coordinates
for (int i = 0; i < 16; i++) { // Draw horizontal line
lcd.setCursor(i, 0);
if (i == x_pos) {
lcd.write((byte)0);
} else {
lcd.write('-');
}
}
for (int i = 0; i < 16; i++) { // Draw vertical line
lcd.setCursor(i, 1);
if (i == y_pos) {
lcd.write((byte)1);
} else {
lcd.write('|');
}
}
delay(100);
}