Acceleration Sensor
The acceleration sensor of the mobile phone is calculated by the offset of the x, Y, z three axes.
The basic API in code is mainly focused on the Accelerometer type
The main thing is to use this type of object to capture readingchanged events to monitor the change in acceleration values.
X, Y, Z acceleration sensing values
1 <StackPanel>2 <TextBoxx:name= "Txtx"Header= "X:"/>3 <TextBoxx:name= "Txty"Header= "Y:"/>4 <TextBoxx:name= "TxtZ"Header= "Z:"/>5 </StackPanel>
1 protected Override voidonnavigatedto (NavigationEventArgs e)2 {3 //get the Sensor object first .4Accelerometer A =Accelerometer.getdefault ();5 if(A = =NULL)6 {7 //represents no accelerometer sensor object8System.Diagnostics.Debug.WriteLine ("Accelerometer sensor not included");9 return;Ten } OneA.readingchanged + =a_readingchanged; AA.reportinterval = A.minimumreportinterval *5; - } - the Async voida_readingchanged (Accelerometer sender, Accelerometerreadingchangedeventargs args) - { -System.Diagnostics.Debug.WriteLine (args +"changed the ... "); - //get the change value + await This. Dispatcher.runasync (Windows.UI.Core.CoreDispatcherPriority.Normal, () = - { +Txtx.text =args. Reading.AccelerationX.ToString (); ATxty.text =args. Reading.AccelerationY.ToString (); atTxtz.text =args. Reading.AccelerationZ.ToString (); - }); -}
Balance Detection
1 <Grid>2 3 <PathData= "m180.348,341.493 l144.279,392.488 l162.935,391.244 l161.692,630.05 l200.249,630.05 L196.517,392.488 L216.418, 393.731 Z "Fill= "#FF6AEA00"HorizontalAlignment= "Center"Height= "289.557"Stretch= "Fill"Stroke= "Black"uselayoutrounding= "False"VerticalAlignment= "Bottom"Width= "73.139"Rendertransformorigin= "0.5,1">4 <Path.rendertransform>5 <Compositetransformx:name= "Rotate"Rotation= "0"/>6 </Path.rendertransform>7 </Path>8 9 </Grid>
1 protected Override voidonnavigatedto (NavigationEventArgs e)2 {3Displayinformation.autorotationpreferences =Displayorientations.landscape;4 //get the Sensor object first .5Accelerometer A =Accelerometer.getdefault ();6 if(A = =NULL)7 {8 //represents no accelerometer sensor object9System.Diagnostics.Debug.WriteLine ("Accelerometer sensor not included");Ten return; One } AA.readingchanged + =a_readingchanged; -A.reportinterval = A.minimumreportinterval *Ten; - } the - Async voida_readingchanged (Accelerometer sender, Accelerometerreadingchangedeventargs args) - { -System.Diagnostics.Debug.WriteLine (args +"changed the ... "); + //get the change value - await This. Dispatcher.runasync (Windows.UI.Core.CoreDispatcherPriority.Normal, () = + { ARotate. Rotation = args. Reading.accelerationy * -; at }); -}
Windows Phone 18, accelerometer