iPhone Development: Programming with the Accelerometer

Integrating the iPhone’s built-in accelerometer into your applications doesn’t require complex programming. Simply implement a UIApplication delegate to receive updates on the device’s orientation changes.

By defining the method (void)acceleratedInX:(float)xx Y:(float)yy Z:(float)zz within any UIApplication, your app will receive periodic updates with the values for X, Y, and Z axes. These values, however, were not quite what I anticipated initially:

X = Roll: The X value indicates the roll, which is the rotation around the axis stretching from your home button to the earpiece.

The roll values range from 0.5 (completely rolled to the left) to -0.5 (completely rolled to the right).

Y = Pitch: Imagine a horizontal line across the middle of your iPhone’s screen while it lies flat on a table. This line represents the axis around which the Y value rotates, ranging from 0.5 (with the headphone jack facing downward) to -0.5 (with the headphone jack facing upward).

Z = Face up/face down: Contrary to my expectations, the Z value does not represent yaw but indicates whether the iPhone is face up (-0.5) or face down (0.5). When the iPhone is on its side, whether by the volume buttons or the opposite, the Z value is 0.0.

I consulted with expert Nate True to better understand these measurements.

He clarified that Z does not measure yaw because yaw is a compass measurement, which the iPhone does not support. Instead, X, Y, and Z measure linear acceleration, pointing towards the direction of gravity. Nate explained, “If you throw the phone into the air, all values will drop to zero.

Dan

Donald is a dedicated writer for TUAW, bringing readers the latest insights and updates on all things Apple. With a keen eye for detail and a love for technology, Donald covers everything from the newest iPhone releases to the latest macOS updates. His articles are known for their clarity and depth, making complex topics accessible to all. When he’s not writing, Donald enjoys exploring the capabilities of his MacBook Pro and capturing moments with his iPhone camera.