/** * Initialise GPIO to echo and trigger pins * * @param triggerGpioNum GPIO connected to the HC-SR04 trigger pin * @param echoGpioNum GPIO connected to the HC-SR04 echo pin * @throws RuntimeIOException if an I/O error occurs */ public HCSR04UsingWait(int triggerGpioNum, int echoGpioNum) throws RuntimeIOException { // Define device for trigger pin at HCSR04 trigger = new DigitalOutputDevice(triggerGpioNum, true, false); // Define device for echo pin at HCSR04 echo = new WaitableDigitalInputDevice(echoGpioNum, GpioPullUpDown.PULL_DOWN, GpioEventTrigger.BOTH); // Sleep for 20 ms - let the device settle? SleepUtil.sleepMillis(20); }