コード例 #1
0
  public static void main(String[] args) throws InterruptedException {
    NXTSoundSensor sound = new NXTSoundSensor(SensorPort.S1);

    LCD.clear();

    while (!Button.ESCAPE.isDown()) {
      // LCD.drawString("SS: " + sound.readValue(), 0, 0);
      // System.out.println("SS: " + sound.readValue());
      Thread.sleep(20);
    }

    LCD.clear();
    System.out.println("EXIT");
    System.exit(0);
  }
コード例 #2
0
ファイル: GUI.java プロジェクト: ThePrimus/LegoPraktikum
  /** Initializes the main menu that enables the user to select a certain obstacle mode. */
  public GUI() {

    LCD.clear(); // Make sure display is clear before the menu is displayed

    // Stop current obstacle program if the left button is pressed
    Button.LEFT.addKeyListener(
        new KeyListener() {
          @Override
          public void keyPressed(Key k) {
            endAllPrograms();
          }

          @Override
          public void keyReleased(Key k) {}
        });

    // Stop program when the escape button is pressed on the ev3 brick
    Button.ESCAPE.addKeyListener(
        new KeyListener() {
          @Override
          public void keyPressed(Key k) {
            drive.stop();

            endAllPrograms();

            // Start the GUI again => main menu should be shown
            // when the obstacle program has been interrupted
            startGUI();
          }

          @Override
          public void keyReleased(Key k) {}
        });

    startGUI();
  }
コード例 #3
0
ファイル: IIERally.java プロジェクト: Knutakir/Legoboys-15
  public static void main(String[] args) throws Exception {

    DifferentialPilot pilot = new DifferentialPilot(56f, 126f, Motor.D, Motor.A);
    pilot.setTravelSpeed(150);

    Brick brick = BrickFinder.getDefault();
    Port s1 = brick.getPort("S1"); //
    Port s4 = brick.getPort("S4"); //

    TextLCD lcd = brick.getTextLCD();

    NXTLightSensor lysSensor = new NXTLightSensor(s1); // NXT LYS
    EV3ColorSensor fargeSensor = new EV3ColorSensor(s4); // EV3 LYS

    // COLOR-----------------------------------------------------------------
    SampleProvider fargeSample = fargeSensor.getColorIDMode();
    float[] colorVerdi = new float[fargeSample.sampleSize()];

    // ----------------------------------------------------------------------

    // LYS-------------------------------------------------------------------
    SampleProvider lysSample = lysSensor;
    float[] lysVerdi = new float[lysSample.sampleSize()];

    // ----------------------------------------------------------------------

    Boolean move = true; // Sett til false hvis roboten ikke skal kjøre videre
    // System.out.println("start lokke");

    while (!Button.ESCAPE.isDown()) { // Kjører så lenge vi ikke trykker på exit-knappen
      // Kjør framover hvis vi ikke allerede gjør det
      if (!pilot.isMoving() && move) {
        pilot.forward();
      }

      lysSensor.fetchSample(lysVerdi, 0); // LYS
      float lys = lysVerdi[0];

      fargeSample.fetchSample(colorVerdi, 0); // COLOR
      // float color = colorVerdi[0];
      int color = fargeSensor.getColorID(); // Fungerer dette?

      lcd.clear();
      lcd.drawString("NXT " + lys, 0, 0);
      lcd.drawString("EV3 " + color, 0, 1);

      if (color != Color.BLACK) {

        pilot.rotate(-10); // VENSTRE
      } else if (lys < 48) {

        // pilot.arcForward(-150);
        pilot.rotate(10);
      }
      // Elsen under trengs ikke, da forward kjøres på starten uansett
      else {
        // pilot.forward();
        if (!pilot.isMoving()) {
          pilot.forward();
        }
      }
    } // while
    System.out.println("AVSLUTTET");
  } // main
コード例 #4
0
 @Override
 public boolean takeControl() {
   return Button.ESCAPE.isDown();
 }