public class HCSR04 extends Object implements DistanceSensorInterface, Closeable
Constructor and Description |
---|
HCSR04(int triggerGpioNum,
int echoGpioNum)
Initialise GPIO to echo and trigger pins
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Free device GPIOs
|
float |
getDistanceCm()
Send a pulse to HCSR04 and compute the echo to obtain distance
|
public HCSR04(int triggerGpioNum, int echoGpioNum) throws RuntimeIOException
triggerGpioNum
- GPIO connected to the HC-SR04 trigger pinechoGpioNum
- GPIO connected to the HC-SR04 echo pinRuntimeIOException
- if an I/O error occurspublic float getDistanceCm() throws RuntimeIOException
getDistanceCm
in interface DistanceSensorInterface
RuntimeIOException
- if an I/O error occurspublic void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2016 mattjlewis. All rights reserved.