How much second its static or in motion?

I have a code MPU6050 motion sensor with esp8266 ,

i try to analysis the values (from mpu6050 register)during motion and static.

then i try to create two conditions,

`if(x>55000||y< 1000 ) {

Serial.print("dynamic");

}

if(x>250&&x<1000||y>64000){

Serial.print("static");

}

and also i try below code to get the actual second its static and dynamic

but not giving correct seconds .

#include <ESP8266WiFi.h> 
#include <MPU6050.h>
int  startTime=0,endTime=0;
double x;
double y;
int SCL_PIN=26;  //5
int SDA_PIN=25;  //4
MPU6050 mpu;
Ticker blinker;

void changeState()
{
Vector rawAccel =mpu.readRawAccel();

x =  rawAccel.XAxis;
y = rawAccel.YAxis;

if(x>250&&x<1000||y>64000)
 { 
 i++;
 Serial.print("static");
 
 Serial.println(i);

 }

 else if(x>900||y<500)    
 {

   j++;
   Serial.print("dynamic");
 
   Serial.println(j);
   
 }

}


void setup()
{
 Serial.begin(9600);
 Serial.println("Initialize MPU6050");

  while(!mpu.beginSoftwareI2C(SCL_PIN,SDA_PIN,MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }
blinker.attach(1, changeState);  //Each 1 second it trigger 

}




void loop()
{

 
}

What you are trying to do with just "X" and "Y" won't work in general. If the sensor is tilted up on its edge, the XY values become XZ or YZ values.

Instead, use vector magnitudes, sqrt(xx + yy + z*z) and see how those values change as you move the sensor. Keep in mind that the sensor always reports the acceleration due to gravity, in addition to other accelerations.

Every time the state changes, record the time in milliseconds. Subtract the previous time the state changed from the current time and add that to the cumulative time of the previous state.

void loop()
{
  unsigned long currentTime = millis();


  static unsigned long previousStateChangeTime = 0;
  static boolean previousIsDynamic = false;
  static unsigned long cumulativeDynamicTime = 0;
  static unsigned long cumulativeStaticTime = 0;


  boolean isDynamic = false;


  // HERE IS WHERE YOU CHECK THE STATE AND SE 'isDynamic" TO 'true' OR 'false'.


  // Look for a state change
  if (isDynamic != previousIsDynamic)
  {
    unsigned long millisInState = currentTime - previousStateChangeTime;
    previousIsDynamic = isDynamic;
    previousStateChangeTime = currentTime;
    if (isDynamic)
    {
      // Was static
      cumulativeStaticTime += millisInState;
    }
    else
    {
      // Was dynamic
      cumulativeDynamicTime += millisInState;
    }
  }
}

If you need the current state cumulative time:

    if (isDynamic)
    {
      Serial.print(cumulativeDynamicTime + (currentTime - previousStateChangeTime));
    }
    else
    {
      Serial.print(cumulativeStaticTime + (currentTime - previousStateChangeTime));
    }