See Also: UIAccelerometer Members
The application developer must always use the UIAccelerometer.SharedAccelerometer property to access the onboard accelerometer. Data in the form of UIKit.UIAcceleration objects can then be read via the UIAccelerometer.Acceleration event, which will fire every UIAccelerometer.UpdateInterval seconds.
In the following example, taken from the "GLPaintGameView" sample, the UIAccelerometer.UpdateInterval is set to 1/25th of a second and the OnAcceleration method is assigned to handle acceleration events. In the handler, the UIKit.UIAccelerometerEventArgs parameter is used to determine the specifics of acceleration:
C# Example
//Configure and enable the accelerometer const int AccelerometerFrequency = 25; UIAccelerometer.SharedAccelerometer.UpdateInterval = 1.0f / AccelerometerFrequency; UIAccelerometer.SharedAccelerometer.Acceleration += OnAccelerated; private void OnAccelerated (object sender, UIAccelerometerEventArgs e) { #if LINQ myAccelerometer = new[]{e.Acceleration.X, e.Acceleration.Y, e.Acceleration.Z} .Select((v, i) => v * FilteringFactor + myAccelerometer [i] * (1.0f - FilteringFactor)) .ToArray (); #else myAccelerometer [0] = e.Acceleration.X * FilteringFactor + myAccelerometer [0] * (1.0 - FilteringFactor); myAccelerometer [1] = e.Acceleration.Y * FilteringFactor + myAccelerometer [1] * (1.0 - FilteringFactor); myAccelerometer [2] = e.Acceleration.Z * FilteringFactor + myAccelerometer [2] * (1.0 - FilteringFactor); #endif ... etc ... }