• 使用手机重量加速器


     Accelerometer sensor;
            private void ApplicationBarMenuItem_Click_2(object sender, EventArgs e)
            {
                //NavigationService.Navigate(new Uri("/Gyroscope_Test.xaml", UriKind.Relative));
                sensor = new Accelerometer() { TimeBetweenUpdates = TimeSpan.FromSeconds(1) };
                sensor.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(sensor_CurrentValueChanged);
                if (sensor.State == SensorState.NotSupported)
                {
                    MessageBox.Show("本手机不支持加速计。");
                    return;
                }
                try
                {
                    sensor.Start();
                }
                catch (AccelerometerFailedException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
    
            void sensor_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
            {
                Dispatcher.BeginInvoke(delegate
                {
                    if (e.SensorReading.Acceleration.X > 0.4)
                    {
                        if (pivot.SelectedIndex == 4)
                        {
                            pivot.SelectedIndex = 0;
                        }
                        else
                        {
                            pivot.SelectedIndex = pivot.SelectedIndex + 1;
                        }
                    }
    
                    if (e.SensorReading.Acceleration.X < -0.4)
                    {
                        if (pivot.SelectedIndex == 0)
                        {
                            pivot.SelectedIndex = 4;
                        }
                        else
                        {
                            pivot.SelectedIndex = pivot.SelectedIndex - 1;
                        }
                    }
    
                    pivot.Title = string.Format("[{0:0.00},{1:0.00},{2:0.00}] at {3}", e.SensorReading.Acceleration.X, e.SensorReading.Acceleration.Y, e.SensorReading.Acceleration.Z, e.SensorReading.Timestamp.TimeOfDay.ToString());
    
                });
            }
  • 相关阅读:
    ColorDialog 组件
    HTTP 错误 404.3
    iis服务器401.3 ACL访问权限问题
    python并发编程(进程操作)
    python并发编程(一些基本概念)
    python网络编程二
    python 网络编程
    python 异常处理
    python模块(hashlib,configparse,logging)
    python面向对象进阶
  • 原文地址:https://www.cnblogs.com/hebeiDGL/p/2471065.html
Copyright © 2020-2023  润新知