Windows Phone 18, accelerometer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.