It was quite simple to get it working in MonoTouch. I created a new view controller with xib and in the Initialize() method I put the following code…
void Initialize ()
{
UIAccelerometer.SharedAccelerometer.UpdateInterval = 0.05;
UIAccelerometer.SharedAccelerometer.Acceleration +=
delegate(object sender, UIAccelerometerEventArgs e)
{
double accelerationX = e.Acceleration.X;
double accelerationY = - e.Acceleration.Y;
double currentRawReading = Math.Atan2(accelerationY, accelerationX);
angle = RadiansToDegrees(currentRawReading);
// Display Angle
lblAngle.Text = angle.ToString();
};
}
private double RadiansToDegrees(double radians)
{
return radians * 180/Math.PI;
}
So there you have it! Enjoy
]]>I’ve had a lot of help along the way from the development community whilst developing our first few apps Techitot Pets for iPhone and Android and Landlubbers for iPhone and Android, so here’s my chance to give something back.
I’ve developed for iOS with Objective-C and X-Code and also C# .Net with MonoTouch. For Android I used Java and Eclipse.
Thanks for checking out my Development Blog
Andrew.
]]>