Jump to content

How to Build and Test an iPhone App that Uses the Accelerometer

+ 2
  Alasdair Allan's Photo
Posted Dec 07 2009 04:13 AM







The sample code (646KB) to accompany the screencast.

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.

Cover of Learning iPhone Programming
Learn more about this topic from Learning iPhone Programming. 

Get the hands-on experience you need to program for the iPhone and iPod Touch. With this easy-to-follow guide, you'll build several sample applications by learning how to use Xcode tools, the Objective-C programming language, and the core frameworks. Before you know it, you'll not only have the skills to develop your own apps, you'll know how to sail through the process of submitting apps to the iTunes App Store.

Learn More Read Now on Safari


1 Reply

 : Dec 17 2009 04:37 PM
You can use the ProCamera iApp: it uses the Accelerometer and a variety of other features:

1. Virtual Horizon
Patent-pending alignment tool
2. Timer
Group Pics, Self-Portraits (gives you a setting between 5-20 seconds)
3. Photo Review + Auto Saving
Review taken photo or snap the next one right away
4. Full size email-Photo sharing
Beat the standard! Send full-sized photos!
5. Digital photo compass
Makes your iPhone 3GS the 1st camera device worldwide providing compass data (oops! I took that photo of my girlfriend but I can’t remember where we were, no worries your camera has already documented your location!).
6. Album-View
Camera Roll access with gesture support
7. Smart Trigger
Tap-Motion-Prevention

Check it out on the AppStore or visit their site at: http://www.procamera-app.com