Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA®
by Nick Lecrenski, Karli Watson, Robert Fonseca-Ensor
ACCELERATING WITH THE ACCELEROMETER
Every Windows Phone 7 device contains an accelerometer, which is basically a motion-detecting sensor. It measures acceleration in three dimensions and makes this information available to applications. This acceleration includes gravity, so the phone knows which way is up (used under the hood for orientation detection) as well as other sources, such as those imparted by a user.
There are a number of uses for accelerometer data, from user interface streamlining to gaming. Games developers in particular have been quick on the uptake, and already there are, for example, driving games that let you steer by tilting a device, and innumerable marble maze–type games.
In this section, you'll see how to access accelerometer data and see some examples of using that data in applications. You'll also look at how to simulate sensor data, which is essential when working in the emulator.
The AccelerometerSensor Sensor
The Windows Phone 7 SDK includes sensor types in the Microsoft.Devices.Sensors namespace, for which you need the Microsoft.Devices.Sensors.dll assembly referenced by your project. At the time of writing, there are four types in this namespace, as shown in Table 6-2.
TABLE 6-2: Sensor Namespace Types

The SensorState enumeration defines a standard set of values for states appropriate to sensors. Table 6-3 shows these values.
TABLE 6-3: SensorState ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access