#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <MPU6050_tockn.h>
// Define the LCD address and dimensions (rows x columns)
#define LCD_ADDRESS 0x27
#define LCD_COLUMNS 16
#define LCD_ROWS 2
// Define MPU6050 address
#define MPU6050_ADDRESS 0x68
// Initialize the LCD
LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS);
// Initialize MPU6050
MPU6050 mpu6050(Wire);
void setup() {
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight();
/*{
lcd.begin(16, 2);
lcd.print(" Vibration");
lcd.setCursor(0, 1);
lcd.print(" Sensor");
}*/
{
static unsigned long lastScrollTime = 0;
static int scrollPosition = 0;
unsigned long currentTime = millis();
if (currentTime - lastScrollTime >= 250) { // Adjust the scroll speed here (500 milliseconds)
lastScrollTime = currentTime;
scrollPosition++;
if (scrollPosition > 10) {
scrollPosition = 0;
}
lcd.clear(); // Clear the LCD screen
lcd.setCursor(scrollPosition, 0);
lcd.print(" Vibration");
lcd.setCursor(scrollPosition, 1);
lcd.print(" Sensor");
}
}
// Initialize MPU6050
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
}
void loop() {
// Read accelerometer and gyroscope data
mpu6050.update();
float ax = mpu6050.getAccX();
float ay = mpu6050.getAccY();
float az = mpu6050.getAccZ();
//float gx = mpu6050.getGyroX();
//float gy = mpu6050.getGyroY();
//float gz = mpu6050.getGyroZ();
// Display accelerometer and gyroscope data on LCD
int x,y,z;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Acc:(in g)");
lcd.print("X:");
lcd.print(ax);
lcd.print(", ");
lcd.setCursor(0, 1);
lcd.print("Y:");
lcd.print(ay);
lcd.print(", ");
lcd.print("Z:");
lcd.print(az);
//lcd.setCursor(0, 1);
//lcd.print("Gyro: ");
//lcd.print(gx);
//lcd.print(", ");
//lcd.print(gy);
//lcd.print(", ");
//lcd.print(gz);
delay(1000);
}