The accelerometer data can be accessed via the AccelerometerReadingEventArgs class. The class has values for the X, Y, and Z axis. The values are of type double and between -2 and 2 which related to acceleration "for each axis in gravitational units" - 1 is the gravitational force of the earth. See: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx and http://msdn.microsoft.com/en-us/library/ff431810(v=vs.92).aspx or on page 80ff, C. Petzold, Programming Windows Phone 7.
A typical exercise for understanding the accelerometer is to create a bubble level (a tool to measure if something is horizontal or vertical - e.g. for hanging pictures on the wall). You probably want to freshen up on arctan2 - at least I needed ;-)
See below the c# example reading out the accelerometer on a windows phone 7. You can also download the accelerometer project directory in a single ZIP-file.
using System; using System.Windows; using Microsoft.Phone.Controls; using Microsoft.Devices.Sensors; // A simple example to read the accelerometer and display the values // In order to make it work you have to add the refercerence to // Microsoft.Devices.Sensors to your project. To do this right-click // in the Solution Explorer on References and than choose add Reference // in the dialog then select Microsoft.Devices.Sensors // Albrecht Schmidt, University of Stuttgart // for a more comprehensive example see: // http://msdn.microsoft.com/en-us/library/ff431810(v=vs.92).aspx // http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx // and page 80ff, C. Petzold, Programming Windows Phone 7 namespace Accl_X_Y_Z { public partial class MainPage : PhoneApplicationPage { Accelerometer accelerometer; public MainPage() { InitializeComponent(); // create a new instance accelerometer = new Accelerometer(); // register a callback function for when values change accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingEventArgs>(accelerometer_ReadingChanged); // start the accelerometer accelerometer.Start(); } void accelerometer_ReadingChanged(object sender, AccelerometerReadingEventArgs e) { // required as from here the textBlocks cannot be accessed Deployment.Current.Dispatcher.BeginInvoke(() => ChangeUI(e)); } void ChangeUI(AccelerometerReadingEventArgs e) { // show the values on the screen textBlock1.Text = "X: " + e.X.ToString("0.000"); textBlock2.Text = "Y: " + e.Y.ToString("0.000"); textBlock3.Text = "Z: " + e.Z.ToString("0.000"); } } }
4 comments:
kanchipuram sarees
kanchipuram Silk sarees
Herbal Powder
golu dolls
kanchipuram silk sarees wholesalers
kanchipuram sarees
kanchipuram silk sarees
kanchipuram silk sarees wholesalers
kanchipuram sarees
kanchipuram silk sarees
kanchipuram silk sarees wholesalers
Herbal Powder
golu dolls
kanchipuram sarees
kanchipuram Silk sarees
Herbal Powder
golu dolls
kanchipuram silk sarees wholesalers
kanchipuram sarees
kanchipuram Silk sarees
Herbal Powder
golu dolls
kanchipuram silk sarees wholesalers
Post a Comment