Accelerometer defines the force applied to the Windows Phone 7 device which can be used to determine the measure of direction that has been applied by the user by moving the device. This values are represented as a 3D vector coordinates in X, Y and Z axis. Using the Accelerometer class present in the library, we can programmatically control the device's 3D acceleration.

 

In this article we will learn about the class that we will use to demonstrate the same feature. Read to learn more about it.

 

Index - Windows Phone 7 (Mango) Tutorial

 

What is Accelerometer and Accelerometer Tool?

Accelerometer sensor present in the hardware device detects the gravitational force applied to the phone due to movement of it. The motion accessed by the APIs to detect the gravity and determine the current pitch and roll of the device. This feature is really very useful if you are developing applications like Game.

 

Using this you can detect the X, Y and Z coordinates and tell your application what to do with the sensor values.

 

If you already installed Mango Tools, the SDK comes with the accelerometer tool integrated with the phone emulator. Using the tool you can virtually test your application in 3D workspace.

 

Here is the screenshot of the tool:

 

WP7.1 Demo - Expanded Accelerometer Window with Phone Emulator

 

In the left side, we have the default emulator. Right side shows the accelerometer tool comes with the phone emulator.

 

Know about Accelerometer class

There is a class called "Accelerometer" that comes with the Windows Phone 7.1 Mango tools. It is present in the namespace called "Microsoft.Devices.Sensors". Here is the class definition of the same:

 

WP7.1 Demo - Accelerometer Class

 

The static property called IsSupported returns whether accelerometer feature is supported by your phone device. The methods named Start() and Stop() are used to enable and disable the functionality in your phone application. Remember that, the Accelerometer class is sealed and hence you can't derive it to a new class to add additional functionality.

 

Know about SensorBase class

Accelerometer derives from abstract class called SensorBase<AccelerometerReading> which takes ISensorReading as values. Here is the class definition:

 

WP7.1 Demo - SensorBase Class

 

CurrentValue property returns the present value of the sensor that the accelerometer is using. TimeBetweenUpdates property sets and returns the value that defines the update frequency of the dimension used by the sensor. IsDataValid returns whether the current value returned by the sensor is valid.

 

In the next post, we will learn about the accelerometer tool that comes with the Windows Phone 7.1 emulator. Till then happy learning.

Have a question? Or, a comment? Let's Discuss it below...

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.