Reading accelerometer data in windows phone 7

Add a reference to the Microsoft.Devices.Sensors assembly, and declare an instance of the Accelerometer class.
Call the Start() method to generate accelerometer readings.

using Microsoft.Devices.Sensors;
 
Accelerometer accelerometer = new Accelerometer(); 
accelerometer.Start(); 
accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(accelerometer_ReadingChanged);

The event handler

void accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e)
{
  float X = (float)e.X;
  float Y = (float)e.Y;
  float Z = (float)e.Z;
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.