Class UltraSonicSensorHelper
java.lang.Object
com.opensourcewithslu.inputdevices.UltraSonicSensorHelper
The UltraSonicSensorHelper class initializes the Ultra Sonic Sensor and provides component functionality
-
Constructor Summary
ConstructorDescriptionUltraSonicSensorHelper
(com.pi4j.io.gpio.digital.DigitalOutput triggerPin, com.pi4j.io.gpio.digital.DigitalInput echoPin) Constructs a new UltraSonicSensorHelper instance. -
Method Summary
Modifier and TypeMethodDescriptiondouble
Returns the distance in centimeters.double
Returns the distance in meters.void
Initializes the Ultrasonic Sensorvoid
Begins measuring distance from sensor calling triggerAndMeasureDistance function every 100 millisecondsvoid
Shuts down ultrasonic sensor
-
Constructor Details
-
UltraSonicSensorHelper
public UltraSonicSensorHelper(com.pi4j.io.gpio.digital.DigitalOutput triggerPin, com.pi4j.io.gpio.digital.DigitalInput echoPin) Constructs a new UltraSonicSensorHelper instance.- Parameters:
triggerPin
- The DigitalOutput pin for triggering the ultrasonic sensor.echoPin
- The DigitalInput pin for receiving the echo from the ultrasonic sensor.
-
-
Method Details
-
initialize
public void initialize()Initializes the Ultrasonic Sensor -
startMeasuring
public void startMeasuring()Begins measuring distance from sensor calling triggerAndMeasureDistance function every 100 milliseconds -
getDistanceInCentimeter
public double getDistanceInCentimeter()Returns the distance in centimeters.- Returns:
- The distance value in centimeters.
-
getDistanceInMeters
public double getDistanceInMeters()Returns the distance in meters.- Returns:
- The distance value in meters.
-
stopMeasuring
public void stopMeasuring()Shuts down ultrasonic sensor
-