Class HC_SR04

java.lang.Object
jpigpio.sensors.HC_SR04

public class HC_SR04
extends java.lang.Object
  • Constructor Summary

    Constructors 
    Constructor Description
    HC_SR04​(JPigpio pigpio, int triggerGpio, int echoGpio)
    Construct the object for this class.
  • Method Summary

    Modifier and Type Method Description
    long getDelay()
    Get the delay in microseconds for a trigger/echo
    double getImperialDistance()
    Get the distance in inches of detection or -1 if no object detected.
    double getMetricDistance()
    Get the sensor measured distance to the target in meters.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HC_SR04

      public HC_SR04​(JPigpio pigpio, int triggerGpio, int echoGpio) throws PigpioException
      Construct the object for this class.
      Parameters:
      pigpio - The reference to the Pigpio controller
      Throws:
      PigpioException
  • Method Details

    • getDelay

      public long getDelay() throws PigpioException
      Get the delay in microseconds for a trigger/echo
      Returns:
      The time in microseconds between a trigger and an echo response
      Throws:
      PigpioException - on pigpiod error
    • getMetricDistance

      public double getMetricDistance() throws PigpioException
      Get the sensor measured distance to the target in meters.
      Returns:
      The distance to the target in meters or -1 if not determined.
      Throws:
      PigpioException - on pigpiod error
    • getImperialDistance

      public double getImperialDistance() throws PigpioException
      Get the distance in inches of detection or -1 if no object detected.
      Returns:
      The distance in inches to object.
      Throws:
      PigpioException - on pigpiod error