Windows phone中的传感器主要包括加速计传感器、罗盘传感器、陀螺仪传感器等加速计传感器 Accelerometer类是加速传感器的接口,Accelerometer类位于Windows.Devices.Sensors命名空间下。 要使用系统加速计的功能,需要创建一个Ac ...
Windows phone中的传感器主要包括加速计传感器、罗盘传感器、陀螺仪传感器等
加速计传感器
Accelerometer类是加速传感器的接口,Accelerometer类位于Windows.Devices.Sensors命名空间下。 要使用系统加速计的功能,需要创建一个Accelerometer类的对象,然后用这个对象来捕获手机当前的加速状态。 Accelerometer类提供了ReadingChanged事件用于检测加速计的状态,并返回X、Y、Z轴信息。
使用Accelerometer类之前要引用Microsoft.Devices.Sensors命名空间。
主要代码如下:
1 using Microsoft.Devices.Sensors; 2 3 namespace accelerometer 4 { 5 public partial class MainPage : PhoneApplicationPage 6 { 7 Accelerometer acc = new Accelerometer(); 8 9 public MainPage()10 {11 InitializeComponent();12 acc.ReadingChanged += acc_ReadingChanged;13 acc.Start();14 }15 16 void acc_ReadingChanged(object sender, AccelerometerReadingEventArgs e)17 {18 Deployment.Current.Dispatcher.BeginInvoke(() => ThreadStaticAccelerometerChanged(e));19 }20 void ThreadStaticAccelerometerChanged(AccelerometerReadingEventArgs e)21 {22 Xtext.Text = e.X.ToString();23 Ytext.Text = e.Y.ToString();24 Ztext.Text = e.Z.ToString();25 }26 }27 }
原标题:windows phone传感器
关键词:Windows
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。