示例#1
0
        private static void TestNXTLight()
        {
            Console.WriteLine("Run NXT Light sensor test on port 4. Uses all the modes and read 100 times.");
            NXTLightSensor nxtlight = new NXTLightSensor(_brick, SensorPort.Port4);
            int            count    = 0;

            while (count < 100)
            {
                Console.WriteLine($"NXT Color Sensor, Raw: {nxtlight.ReadRaw()}, ReadASString: {nxtlight.ReadAsString()}, NumberNodes: {nxtlight.NumberOfModes()}, SensorName: {nxtlight.GetSensorName()}");
                Console.WriteLine($"Color: {nxtlight.ReadRaw()}");
                Thread.Sleep(300);
                count++;
            }

            count = 0;
            nxtlight.SelectNextMode();
            while (count < 100)
            {
                Console.WriteLine($"NXT Color Sensor, Raw: {nxtlight.ReadRaw()}, ReadASString: {nxtlight.ReadAsString()}, NumberNodes: {nxtlight.NumberOfModes()}, SensorName: {nxtlight.GetSensorName()}");
                Console.WriteLine($"Color: {nxtlight.ReadRaw()}");
                Thread.Sleep(300);
                count++;
            }
        }
示例#2
0
        private async Task TestNXTLight()
        {
            //NXTTouchSensor touch = new NXTTouchSensor(BrickPortSensor.PORT_S2);
            //EV3TouchSensor ev3Touch = new EV3TouchSensor(BrickPortSensor.PORT_S1);
            //NXTSoundSensor sound = new NXTSoundSensor(BrickPortSensor.PORT_S4);
            NXTLightSensor nxtlight = new NXTLightSensor(brick, BrickPortSensor.PORT_S4);
            int            count    = 0;

            while (count < 100)
            {
                //Debug.WriteLine(string.Format("NXT Touch, Raw: {0}, ReadASString: {1}, IsPressed: {2}, NumberNodes: {3}, SensorName: {4}", touch.ReadRaw(), touch.ReadAsString(), touch.IsPressed(), touch.NumberOfModes(), touch.GetSensorName()));
                //Debug.WriteLine(string.Format("EV3 Touch, Raw: {0}, ReadASString: {1}, IsPressed: {2}, NumberNodes: {3}, SensorName: {4}", ev3Touch.ReadRaw(), ev3Touch.ReadAsString(), ev3Touch.IsPressed(), ev3Touch.NumberOfModes(), ev3Touch.GetSensorName()));
                //Debug.WriteLine(string.Format("NXT Sound, Raw: {0}, ReadASString: {1}, NumberNodes: {2}, SensorName: {3}", sound.ReadRaw(), sound.ReadAsString(), sound.NumberOfModes(), sound.GetSensorName()));
                Debug.WriteLine(string.Format("NXT Color Sensor, Raw: {0}, ReadASString: {1}, NumberNodes: {2}, SensorName: {3}",
                                              nxtlight.ReadRaw(), nxtlight.ReadAsString(), nxtlight.NumberOfModes(), nxtlight.GetSensorName()));
                Debug.WriteLine(string.Format("Color: {0}, ",
                                              nxtlight.ReadRaw()));

                await Task.Delay(300);

                //if ((touch.IsPressed()) && ev3Touch.IsPressed())
                count++;
            }
            count = 0;
            nxtlight.SelectNextMode();
            while (count < 100)
            {
                //Debug.WriteLine(string.Format("NXT Touch, Raw: {0}, ReadASString: {1}, IsPressed: {2}, NumberNodes: {3}, SensorName: {4}", touch.ReadRaw(), touch.ReadAsString(), touch.IsPressed(), touch.NumberOfModes(), touch.GetSensorName()));
                //Debug.WriteLine(string.Format("EV3 Touch, Raw: {0}, ReadASString: {1}, IsPressed: {2}, NumberNodes: {3}, SensorName: {4}", ev3Touch.ReadRaw(), ev3Touch.ReadAsString(), ev3Touch.IsPressed(), ev3Touch.NumberOfModes(), ev3Touch.GetSensorName()));
                //Debug.WriteLine(string.Format("NXT Sound, Raw: {0}, ReadASString: {1}, NumberNodes: {2}, SensorName: {3}", sound.ReadRaw(), sound.ReadAsString(), sound.NumberOfModes(), sound.GetSensorName()));
                Debug.WriteLine(string.Format("NXT Color Sensor, Raw: {0}, ReadASString: {1}, NumberNodes: {2}, SensorName: {3}",
                                              nxtlight.ReadRaw(), nxtlight.ReadAsString(), nxtlight.NumberOfModes(), nxtlight.GetSensorName()));
                Debug.WriteLine(string.Format("Color: {0}, ",
                                              nxtlight.ReadRaw()));

                await Task.Delay(300);

                //if ((touch.IsPressed()) && ev3Touch.IsPressed())
                count++;
            }
        }