public class HCSR04UsingEvents extends Object implements DistanceSensorInterface, InputEventListener<DigitalInputEvent>
Constructor and Description |
---|
HCSR04UsingEvents(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
|
void |
valueChanged(DigitalInputEvent event) |
public HCSR04UsingEvents(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 SensorInterface
close
in interface Closeable
close
in interface AutoCloseable
public void valueChanged(DigitalInputEvent event)
valueChanged
in interface InputEventListener<DigitalInputEvent>
Copyright © 2016–2018 mattjlewis. All rights reserved.