An accelerometer is a sensor that can measure the intensity and direction of the acceleration force that the phone experiences. The intensity reading is provided as a decimal value ranging from -1.0 to 1.0 for the X, Y, and Z axes on the phone. This sensor monitors the acceleration force experienced width-wise, length-wise, and depth-wise. In order to detect the direction of force, the X, Y, and Z values must be compared to one another.
Let's create a demo app to understand how to use the accelerometer sensor:
Create a new project of the type F# Windows Phone Application (Silverlight) and give it a name.
Right-click on the App project and add a reference to Microsoft.Devices.Sensors from the list.
In
MainPage.xaml
, add three text blocks to display theX
,Y
, andZ
reading. The XAML snippet for the same is shown as follows:<TextBlock Height="30" HorizontalAlignment="Left" Margin="20,100,0,0" Name="xTextBlock" Text="X: 1.0" VerticalAlignment="Top" ...