#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MPU6050.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
MPU6050 mpu;
void setup() {
Wire.begin();
// Initialize OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
// Initialize MPU6050
mpu.initialize();
display.setCursor(0,0);
display.print("MR.MONITOR");
}
void loop() {
int16_t ax, ay, az;
mpu.getAcceleration(&ax, &ay, &az);
display.clearDisplay(); // Clear the previous content
if (ax > 15000 && ay > 15000 && az > 15000) {
display.setCursor(0, 0);
display.print("Warning!");
} else {
display.setCursor(0, 0);
display.print("All is OK");
}
display.display(); // Update the display
delay(1000);
}