Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Accelerometer in Xamarin.Forms Applications
private void BtnStart_OnClicked(object sender, EventArgs e)
{
CrossDeviceMotion.Current.Start(MotionSensorType.Accelerometer, MotionSensorDelay.Ui);
CrossDeviceMotion.Current.SensorValueChanged += (s, a) =>
{
switch (a.SensorType)
{
case MotionSensorType.Accelerometer:
lblXAxis.Text = ((MotionVector)a.Value).X.ToString("F");
lblYAxis.Text = ((MotionVector)a.Value).Y.ToString("F");
lblZAxis.Text = ((MotionVector)a.Value).Z.ToString("F");
break;
}
};
}
private void BtnStop_OnClicked(object sender, EventArgs e)
{
CrossDeviceMotion.Current.Stop(MotionSensorType.Accelerometer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.