Sample Code (646KB) to accompany the screencast.


Mobile phones aren?t just about making phone calls anymore. The iPhone, like a lot of high-end smart phones these days, comes with a number of sensors: camera, accelerometer, GPS module, and digital compass. We?re entering a period of change, more and more users expect these sensors to be integrated into the ?application experience?. If you application can make use of them, it probably should.

The iPhone?s accelerometer measures the linear acceleration of the device so can report the roll and pitch, but not the yaw, of the device. However if you are dealing with an iPhone 3GS, which has a digital compass, you can combine the accelerometer and magnetometer readings to have roll, pitch and yaw measurements (see the following section for details of how to access the magnetometer).

The accelerometer reports three figures: X, Y and Z, acceleration values for each axis are reported directly by the hardware as G-force values. Therefore a value of 1.0 represents a load of approximately 1-gravity. While X therefore corresponds to roll, and Y to pitch, the Z value corresponds to whether the device is front-side-up or front-side-down, with a value of 0.0 being reported when the iPhone is edge-on.

This screencast shows how to put together the Accelerometer application which I talked about in the Chapter 10 of the book.

Read More


"Learning iPhone Programming" is published by O'Reilly Media.