#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MPU6050.h>
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
int a;
bool status;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
// set I2C address of MPU6050 sensor
Adafruit_MPU6050 mpu;
void setup(){
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
sensors_event_t event;
void loop(){
status = mpu.begin(0x68);
mpu.begin(0x68);
mpu.getAccelerometerSensor()->getEvent(&event);
// set cursor to first column, first row
// print message
lcd.setCursor(0,0);
lcd.print("acceleration");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("x =");
lcd.print(event.acceleration.x);
delay(1000);
// clears the display to print new message
// lcd.clear();
lcd.setCursor(9,0);
lcd.print("y =");
lcd.print(event.acceleration.y);
delay(1000);
// clears the display to print new message
// lcd.clear();
lcd.setCursor(0,1);
lcd.print("z =");
lcd.print(event.acceleration.z);
delay(1000);
// clears the display to print new message
lcd.clear();
// set cursor to first column, second row
lcd.setCursor(1,1);
lcd.print("Hello, World!");
delay(1000);
lcd.clear();
if (status ==1)
{
lcd.print("yes");
delay(1000);
lcd.clear();
}
else
{
lcd.print("no");
delay(1000);
lcd.clear();
}
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4