Accelerometer Displacement

You would do this by numerical integration.

The change in speed over a time interval is the average acceleration multiplied by the duration. This is very convenient to evaluate iteratively:

currentAcceleration = readAcceleration();
averageAcceleration = (currentAcceleration + previousAcceleration) / 2;

currentSpeed = previousSpeed + (averageAcceleration * duration);
averageSpeed = (currentSpeedĀ  + previousSpeed) / 2;

currentDisplacement = previousDisplacement + (averageSpeed * duration);

previousAcceleration = currentAcceleration;
previousSpeed = currentSpeed ;
previousDisplacement = currentDisplacement;

You would need to execute that code periodically. The blink without delay example shows how to do that.

You will need to deal with scaling according to the units that you're using for acceleration, speed, distance and time.