Exemplo n.º 1
0
        //EV3IRSensor
        private async Task TestIRSensor()
        {
            EV3IRSensor ultra = new EV3IRSensor(brick, BrickPortSensor.PORT_S4, IRMode.Remote);

            int count = 0;

            while (count < 100)
            {
                Debug.WriteLine(string.Format("NXT ultra, Remote: {0}, ReadAsString: {1}, NumberNodes: {2}, SensorName: {3}",
                                              ultra.Value, ultra.ReadAsString(), ultra.Mode, ultra.GetSensorName()));
                await Task.Delay(300);

                count++;
            }
            ultra.Mode = IRMode.Proximity;
            count      = 0;
            while (count < 10)
            {
                Debug.WriteLine(string.Format("NXT ultra, Remote: {0}, ReadAsString: {1}, NumberNodes: {2}, SensorName: {3}",
                                              ultra.Value, ultra.ReadAsString(), ultra.Mode, ultra.GetSensorName()));
                await Task.Delay(300);

                count++;
            }
            ultra.Mode = IRMode.Seek;
            count      = 0;
            while (count < 10)
            {
                Debug.WriteLine(string.Format("NXT ultra, Remote: {0}, ReadAsString: {1}, NumberNodes: {2}, SensorName: {3}",
                                              ultra.Value, ultra.ReadAsString(), ultra.Mode, ultra.GetSensorName()));
                await Task.Delay(300);

                count++;
            }
        }
Exemplo n.º 2
0
        //EV3IRSensor
        private async Task TestIRSensor()
        {
            EV3IRSensor ultra = new EV3IRSensor(BrickPortSensor.PORT_S4, IRMode.Remote);

            for (int i = 0; i < ultra.NumberOfModes(); i++)
            {
                int count = 0;
                while (count < 100)
                {
                    Debug.WriteLine(string.Format("NXT ultra, Distance: {0}, ReadAsString: {1}, NumberNodes: {2}, SensorName: {3}",
                                                  ultra.ReadBeaconLocation(), ultra.ReadAsString(), ultra.Mode, ultra.GetSensorName()));
                    await Task.Delay(300);
                }
                ultra.SelectNextMode();
            }
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            IRChannel[] channels = { IRChannel.One, IRChannel.Two, IRChannel.Three, IRChannel.Four };

            int channelIdx = 0;
            ManualResetEvent terminateProgram = new ManualResetEvent(false);
            var          sensor = new EV3IRSensor(SensorPort.In1);
            ButtonEvents buts   = new ButtonEvents();

            LcdConsole.WriteLine("Use IR on port1");
            LcdConsole.WriteLine("Up distance");
            LcdConsole.WriteLine("Down beacon location");
            LcdConsole.WriteLine("Enter read command");
            LcdConsole.WriteLine("Left change channel");
            LcdConsole.WriteLine("Right read as string");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };
            buts.UpPressed += () => {
                LcdConsole.WriteLine("Distance " + sensor.ReadDistance() + " cm");
            };
            buts.EnterPressed += () => {
                LcdConsole.WriteLine("Remote command " + sensor.ReadRemoteCommand() + " on channel " + sensor.Channel);
            };
            buts.DownPressed += () => {
                BeaconLocation location = sensor.ReadBeaconLocation();
                LcdConsole.WriteLine("Beacon location: " + location.Location + " Beacon distance: " + location.Distance + " cm");
            };
            buts.LeftPressed += () => {
                channelIdx     = (channelIdx + 1) % channels.Length;
                sensor.Channel = channels[channelIdx];
                LcdConsole.WriteLine("Channel is set to: " + channels[channelIdx]);
            };
            buts.RightPressed += () => {
                LcdConsole.WriteLine(sensor.ReadAsString());
            };
            terminateProgram.WaitOne();
        }