Jump to content

How to calibrate the iPhone Accelerometer for optimal use.

+ 3
  Paul Zirkle's Photo
Posted Nov 10 2009 10:51 AM

The accelerometer returns 3-dimensions of input (x,y, and z axis). However, the native state of the accelerometer input is with the iPhone being held flat, parallel to the ground (such as if it were lying on a table).

This position is uncomfortable for most people, as they will naturally be holding the phone at an angle, which will result in a constant non-zero value from one or more of your input axis. The best way to solve this problem is to allow the user to "calibrate" the accelerometer to the natural angle they are holding the phone at.

Do this by providing a "calibration button" perhaps in an options screen. When the button is pressed, record the accelerometer values. Now you can subtract these values from any further accelerometer input to "normalize" it to the new default orientation.

An implementation of this concept can be found in my book, "iPhone Game Development".

Cover of iPhone Game Development
Learn more about this topic from iPhone Game Development. 

What do you need to know to create a game for the iPhone? Even if you've already built some iPhone applications, developing games using iPhone's gestural interface and limited screen layout requires new skills. Loaded with descriptive examples and clear explanations, iPhone Game Development provides everything from game development basics and iPhone programming fundamentals to guidelines for dealing with special graphics and audio needs, creating in-game physics, and much more.

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies