@Override public void action() { boolean exit = false; // LCD.clear(); LCD.drawString("Press UP for Menu", 0, 0); LCD.drawString("Press DOWN for EXIT", 0, 1); this.hal.stop(); while (!exit) { Delay.msDelay(50); if (Button.UP.isDown()) { // Sound.beep(); // this lets the arbitrator exit and the main while-loop continues sharedState.setState(MyState.ExitState); exit = true; } else if (Button.DOWN.isDown()) { this.hal.destroy(); System.exit(0); } } }
public void testOne() { ColorAdapter adapter = new ColorAdapter(new EV3ColorSensor(SensorPort.S1)); while (!Button.DOWN.isDown()) { Color c = adapter.getColor(); String str = "r=" + c.getRed() + ",g=" + c.getGreen() + ",b=" + c.getBlue(); log.echo(str); Delay.msDelay(1000); if (adapter.getColorID() == Color.BLUE) break; } }
public void test() { EV3ColorSensor sensor = new EV3ColorSensor(SensorPort.S1); // 模式一:ColorID,一个数 // SensorMode mode = sensor.getColorIDMode(); // 模式二:RGB,三个数 // SensorMode mode = sensor.getRGBMode(); // 模式三:环境光,一个数,大则亮,小则暗 // SensorMode mode = sensor.getAmbientMode(); // 模式四:测量,一个数,大则近,0则远 SensorMode mode = sensor.getRedMode(); float[] samples = new float[mode.sampleSize()]; while (!Button.DOWN.isDown()) { mode.fetchSample(samples, 0); int k = 0; for (float v : samples) log.echo("v[" + (k++) + "]=" + v); } sensor.close(); }