Package lejos.hardware.sensor
Class EV3UltrasonicSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.UARTSensor
-
- lejos.hardware.sensor.EV3UltrasonicSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorMode,SensorModes,SampleProvider
public class EV3UltrasonicSensor extends UARTSensor
Lego EV3 Ultrasonic sensor
The EV3 Ultrasonic sensor measures distance to an object in front of the sensor. It can also be used to detect other (active) Ultrasonic sensors in the vicinity.Supported modes Mode name Description unit(s) Getter Distance Measures distance to an object in front of the sensor Meter getDistanceMode()Listen Listens for other ultrasonic sensors Boolean getListenMode()Sensor configuration
The sensor can be switched off and on using theenable()anddisable()methods. Disabling the sensor also shuts down the lights.See Sensor Product page See The leJOS sensor framework See
leJOS conventions for SampleProviders- Author:
- Aswin Bouwmeester
-
-
Field Summary
-
Fields inherited from class lejos.hardware.sensor.UARTSensor
currentMode, port
-
Fields inherited from class lejos.hardware.sensor.BaseSensor
modes
-
-
Constructor Summary
Constructors Constructor Description EV3UltrasonicSensor(Port port)Create the Ultrasonic sensor class.EV3UltrasonicSensor(UARTPort port)Create the Ultrasonic sensor class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddisable()Disable the sensor.voidenable()Enable the sensor.SampleProvidergetDistanceMode()Lego EV3 Ultrasonic sensor, Distance mode
Measures distance to an object in front of the sensorSampleProvidergetListenMode()Lego EV3 Ultrasonic sensor, Listen mode
Listens for the presence of other ultrasonic sensors.protected voidinit()booleanisEnabled()Indicate that the sensor is enabled.-
Methods inherited from class lejos.hardware.sensor.UARTSensor
switchMode
-
Methods inherited from class lejos.hardware.sensor.BaseSensor
fetchSample, getAvailableModes, getCurrentMode, getMode, getMode, getModeCount, getName, sampleSize, setCurrentMode, setCurrentMode, setModes
-
Methods inherited from class lejos.hardware.Device
close, releaseOnClose
-
-
-
-
Method Detail
-
init
protected void init()
-
getListenMode
public SampleProvider getListenMode()
Lego EV3 Ultrasonic sensor, Listen mode
Listens for the presence of other ultrasonic sensors.Size and content of the sample
The sample contains one elements indicating the presence of another ultrasonic sensor. A value of 1 indicates that the sensor detects another ultrasonic sensor.- Returns:
- A sampleProvider
-
getDistanceMode
public SampleProvider getDistanceMode()
Lego EV3 Ultrasonic sensor, Distance mode
Measures distance to an object in front of the sensorSize and content of the sample
The sample contains one elements representing the distance (in metres) to an object in front of the sensor. unit).- Returns:
- A sampleProvider
-
enable
public void enable()
Enable the sensor. This puts the indicater LED on.
-
disable
public void disable()
Disable the sensor. This puts the indicater LED off.
-
isEnabled
public boolean isEnabled()
Indicate that the sensor is enabled.- Returns:
- True, when the sensor is enabled.
False, when the sensor is disabled.
-
-