Delay

Delay (io.github.jabrena.juno.util) pauses the program for a fixed amount of time. It has three static methods:

Method Pauses for
Delay.millis(n) n milliseconds
Delay.micros(n) n microseconds
Delay.seconds(n) n seconds

A value of zero or less returns at once, so a delay can be computed without checking it first.

Blinking an LED

The classic example pauses for half a second in each state:

import io.github.jabrena.juno.hardware.ArduinoUno;
import io.github.jabrena.juno.hardware.gpio.DigitalOutput;
import io.github.jabrena.juno.util.Delay;

public class Blink {

    public static void main(String[] args) {
        DigitalOutput led = DigitalOutput.of(ArduinoUno.getGpio().getBuiltinLed());

        while (true) {
            led.high();
            Delay.millis(500);
            led.low();
            Delay.millis(500);
        }
    }
}

Short pauses with micros

Delay.micros is for pauses shorter than a millisecond, such as the timing of a single signal edge:

led.high();
Delay.micros(10);   // 10 microseconds
led.low();

Longer pauses with seconds

Delay.seconds is a convenience over Delay.millis, for pauses measured in whole seconds:

Delay.seconds(2);   // the same as Delay.millis(2000)