Skip to content
johnmeshulam edited this page Nov 10, 2019 · 2 revisions

The Wait class provides you with two useful methods for flow control:

  1. Wait.waitForSeconds(double seconds)

  2. Wait.waitFor(WaitCondition condition)

waitForSeconds

The waitForSeconds() method is pretty straightforward - You supply it with a double representing the seconds it should wait, and it... waits.

Example:

Wait.waitForSeconds(3.2);

Why not use Thread.sleep() or leJOS's native Delay.msdelay()?

These functions do not integrate with FLL-leJOS' run interruptions, so you might get stuck in a blocking call and not be able to stop your robot during a match.

waitFor

The waitFor() method is an extremely powerful tool. Using waitFor you can safely wait for any boolean condition without worrying about getting stuck in a blocking call.

Syntax

Wait.waitFor(() -> {
<write a Java method here. This method must return a boolean condition.>
});

Example:

Wait.waitFor(() -> {
    return Button.getButtons() == Button.ID_ENTER;
});

The example above uses a combination of FLL-leJOS' wait function and vanilla leJOS' Button class to wait until the center button on the EV3 is pressed.

Clone this wiki locally