Package com.diozero.devices
Class GP2Y0A21YK
java.lang.Object
com.diozero.api.GpioDevice
com.diozero.api.GpioInputDevice<AnalogInputEvent>
com.diozero.api.AnalogInputDevice
com.diozero.devices.GP2Y0A21YK
- All Implemented Interfaces:
DeviceEventConsumer<AnalogInputEvent>
,DistanceSensorInterface
,SensorInterface
,Closeable
,AutoCloseable
,Runnable
,Consumer<AnalogInputEvent>
public class GP2Y0A21YK extends AnalogInputDevice implements DistanceSensorInterface
Sharp GP2Y0A21YK distance sensor. Datasheet, Guide. Important to supply 5V to get correct readings (max output voltage ~3.2V).
Range: 10 to 80 cm Typical response time: 39 ms Typical start up delay: 44 ms Average Current Consumption: 30 mA Detection Area Diameter @ 80 cm: 12 cm Supply voltage : 4.5 to 5.5 V
-
Field Summary
Fields inherited from class com.diozero.api.GpioDevice
gpio
-
Constructor Summary
Constructors Constructor Description GP2Y0A21YK(int gpio)
GP2Y0A21YK(AnalogInputDeviceFactoryInterface deviceFactory, int gpio)
-
Method Summary
Modifier and Type Method Description float
getDistanceCm()
Read distance in centimetres, range 10 to 80cm.Methods inherited from class com.diozero.api.AnalogInputDevice
accept, addListener, addListener, close, convertToScaledValue, disableDeviceListener, enableDeviceListener, getRange, getScaledValue, getUnscaledValue, run
Methods inherited from class com.diozero.api.GpioInputDevice
addListener, removeAllListeners, removeListener
Methods inherited from class com.diozero.api.GpioDevice
getGpio
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.devices.SensorInterface
close
-
Constructor Details
-
GP2Y0A21YK
- Throws:
RuntimeIOException
-
GP2Y0A21YK
public GP2Y0A21YK(AnalogInputDeviceFactoryInterface deviceFactory, int gpio) throws RuntimeIOException- Throws:
RuntimeIOException
-
-
Method Details
-
getDistanceCm
Read distance in centimetres, range 10 to 80cm.- Specified by:
getDistanceCm
in interfaceDistanceSensorInterface
- Returns:
- Distance, range 10 to 80cm.
- Throws:
RuntimeIOException
-