Accelerometer, help

I am new with sensors such as accelerometers, therefore, I decided to check the code in the examples section. I always want to understand the code before I use it, so I read it and did not understand this part...

/*
Memsic2125

Read the Memsic 2125 two-axis accelerometer. Converts the
pulses output by the 2125 into milli-g's (1/1000 of earth's
gravity) and prints them over the serial connection to the
computer.

The circuit:

  • X output of accelerometer to digital pin 2
  • Y output of accelerometer to digital pin 3
  • +V of accelerometer to +5V
  • GND of accelerometer to ground

created 6 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe

This example code is in the public domain.

*/

// these constants won't change:
const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer

void setup() {
// initialize serial communications:
Serial.begin(9600);
// initialize the pins connected to the accelerometer
// as inputs:
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
}

void loop() {
// variables to read the pulse widths:
int pulseX, pulseY;
// variables to contain the resulting accelerations
int accelerationX, accelerationY;

// read pulse from x- and y-axes:
pulseX = pulseIn(xPin,HIGH);
pulseY = pulseIn(yPin,HIGH);

// convert the pulse width into acceleration
// accelerationX and accelerationY are in milli-g's:
// earth's gravity is 1000 milli-g's, or 1g.
accelerationX = ((pulseX / 10) - 500) * 8;
accelerationY = ((pulseY / 10) - 500) * 8;

// print the acceleration
Serial.print(accelerationX);
// print a tab character:
Serial.print("\t");
Serial.print(accelerationY);
Serial.println();

delay(100);
}

I what unit is PulseX and Y measured in order to do the formula?
What is the logic of PulseX and Y, AccelerationX and Y?

Thank you in advance

Alrro

Look at the Memsic2125 datasheet:

Each cycle of the output is 10 mS (10,000 uS). This gives a mid-range 0 g value of 5 mS (5000 uS).

The high part of the cycle is 1250 uS per g. Multiply by 8 to get 10,000'ths of a g.

The /10 would be to convert from 10,000 per g to 1,000 per g (a.k.a. milli-g).

The -500 is to center the 0-1,000 milli-g range allowing for negative g's.

The memsic2125 is from 2008 or so. That is like the stone-age for accelerometers.
I suggest you drop your Fred Flinstone accelerometer and buy a normal one. Most newer accelerometers are cheaper and better and have 3 axis.