示例#1
0
        private void SpeedChangeTest()
        {
            Console.WriteLine("+GY521 Speed Change Test");

            var i2c = Device.CreateI2cBus();

            var gyro = new GY521(i2c);

            Console.WriteLine(" Wake");
            gyro.Wake();

            var count = 0;

            while (true)
            {
                try
                {
                    Console.WriteLine($" Reading @{i2c.Frequency.Kilohertz} kHz...");
                    gyro.Refresh();

                    Console.WriteLine($" ({gyro.AccelerationX:X4},{gyro.AccelerationY:X4},{gyro.AccelerationZ:X4}) ({gyro.GyroX:X4},{gyro.GyroY:X4},{gyro.GyroZ:X4}) {gyro.Temperature}");

                    switch (count++ % 4)
                    {
                    case 0:
                        i2c.Frequency = new Meadow.Units.Frequency(100000, Meadow.Units.Frequency.UnitType.Hertz);
                        break;

                    case 1:
                        i2c.Frequency = new Meadow.Units.Frequency(400000, Meadow.Units.Frequency.UnitType.Hertz);
                        break;

                    case 2:
                        i2c.Frequency = new Meadow.Units.Frequency(1000000, Meadow.Units.Frequency.UnitType.Hertz);
                        break;

                    case 3:
                        i2c.Frequency = new Meadow.Units.Frequency(3400000, Meadow.Units.Frequency.UnitType.Hertz);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($" Error: {ex.Message}");
                }

                Thread.Sleep(2000);
            }
        }
示例#2
0
        private void GY521Test()
        {
            var i2c = Device.CreateI2cBus();

            Console.WriteLine("+GY521 Test");

            var gyro = new GY521(i2c);

            Console.WriteLine(" Wake");
            gyro.Wake();

            while (true)
            {
                Console.WriteLine(" Reading...");
                gyro.Refresh();

                Console.WriteLine($" ({gyro.AccelerationX:X4},{gyro.AccelerationY:X4},{gyro.AccelerationZ:X4}) ({gyro.GyroX:X4},{gyro.GyroY:X4},{gyro.GyroZ:X4}) {gyro.Temperature}");

                Thread.Sleep(2000);
            }
        }