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:
DeviceInterface
,DeviceEventConsumer<AnalogInputEvent>
,DistanceSensorInterface
,SensorInterface
,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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.diozero.api.AnalogInputDevice
AnalogInputDevice.Builder
-
-
Field Summary
-
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
-
Constructor Summary
Constructors Constructor Description GP2Y0A21YK(int gpio)
GP2Y0A21YK(AnalogInputDeviceFactoryInterface deviceFactory, int gpio)
-
Method Summary
All Methods Instance Methods Concrete Methods 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, hasListeners, 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.api.DeviceInterface
close
-
-
-
-
Constructor Detail
-
GP2Y0A21YK
public GP2Y0A21YK(int gpio) throws RuntimeIOException
- Throws:
RuntimeIOException
-
GP2Y0A21YK
public GP2Y0A21YK(AnalogInputDeviceFactoryInterface deviceFactory, int gpio) throws RuntimeIOException
- Throws:
RuntimeIOException
-
-
Method Detail
-
getDistanceCm
public float getDistanceCm() throws RuntimeIOException
Read distance in centimetres, range 10 to 80cm.- Specified by:
getDistanceCm
in interfaceDistanceSensorInterface
- Returns:
- Distance, range 10 to 80cm.
- Throws:
RuntimeIOException
-
-