#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <TM1637.h>
#include <math.h>

//MPU stuff begin
Adafruit_MPU6050 mpu;
int x = 0;
int y = 0;
int z = 0;
//MPU stuff End

//7 Segment stuff begin
const int CLK = 2;
const int DIO = 3;
TM1637 tm(CLK, DIO);
//7 Segment stuff End

void setup(void) {//void argument for mpu code only
  //MPU Code Begin
  Serial.begin(115200);

  while (!mpu.begin()) {
    Serial.println("MPU6050 not connected!");
    delay(1000);
  }
  Serial.println("MPU6050 ready!");
  //MPU Code End

  //7Segment Code Begin
    tm.init();
    tm.set(BRIGHT_TYPICAL);
  //7 Segment Code End
}
//MPU stuff
sensors_event_t event;

//7 Segment stuff
unsigned int counter = 0;

void loop() {
  //MPU Program Begin
  mpu.getAccelerometerSensor()->getEvent(&event);

  Serial.print("[");
  Serial.print(millis());
  Serial.print("] X: ");
  x = Serial.print(event.acceleration.x);
  Serial.print(", Y: ");
  y = Serial.print(event.acceleration.y);
  Serial.print(", Z: ");
  z = Serial.print(event.acceleration.z);
  Serial.println(" m/s^2");
  delay(500);
  //MPU Program end
  
  //7 Segment display Program Begin
    tm.display(0, x);
    tm.display(1, y);
    tm.display(2, z);
    tm.display(3, 0);

  counter++;
  if (counter == 6) {
    counter = 0;
  }

  delay(1000);
  //7 Segment display Program End
}
4-Digit Display