How to Calibrate Iphone Accelerometer

I am using this code to move an object with the accelerometer:

var dir : Vector3 =;

dir.x = -Input.acceleration.y; 
dir.z = Input.acceleration.x;

dir = dir * 3;

if(dir.sqrMagnitude > 1)
filter = Vector3.Lerp(filter, dir, 7*Time.deltaTime);

dir = filter * Time.deltaTime;

transform.Translate(dir * speed);

I want a calibrate button so the player doesn’t have to hold the phone parallel to the ground. I just don’t know what I actually need to do in order to calibrate it.

Just place a button that will freeze everything else. Then, when activated this button should display another button telling the player to hold the device still in the desired position. When this other button is clicked, store the accelerometer reading and use it as offset together with the realtime readings.