public class EV3UltrasonicSensor extends BaseSensor
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 the enable()
and
disable()
methods. Disabling the sensor also shuts down the lights.
See Sensor Product page
See The
leJOS sensor framework
See leJOS conventions for
SampleProviders
Modifier and Type | Class and Description |
---|---|
private class |
EV3UltrasonicSensor.DistanceMode |
private class |
EV3UltrasonicSensor.ListenMode
Represents a Ultrasonic sensor in listen mode
|
Modifier and Type | Field and Description |
---|---|
private static int |
DISABLED |
private static int |
SWITCHDELAY |
currentMode, currentModeS, modes
PATH_DEVICE
Constructor and Description |
---|
EV3UltrasonicSensor(java.lang.String portName)
Create the Ultrasonic sensor class.
|
Modifier and Type | Method and Description |
---|---|
void |
disable()
Disable the sensor.
|
void |
enable()
Enable the sensor.
|
SampleProvider |
getDistanceMode()
Lego EV3 Ultrasonic sensor, Distance mode
Measures distance to an object in front of the sensor Size and content of the sample The sample contains one elements representing the distance (in metres) to an object in front of the sensor. |
SampleProvider |
getListenMode()
Lego EV3 Ultrasonic sensor, Listen mode
Listens for the presence of other ultrasonic sensors. |
protected void |
init() |
boolean |
isEnabled()
Indicate that the sensor is enabled.
|
fetchSample, getAvailableModes, getCurrentMode, getMode, getMode, getModeCount, getName, sampleSize, setCurrentMode, setCurrentMode, setModes, switchMode, switchMode
connect, getIntegerAttribute, getStringAttribute, setIntegerAttribute, setStringAttribute
getElements, readFloat, readInteger, readString, writeInteger, writeString
close, releaseOnClose
private static final int DISABLED
private static final int SWITCHDELAY
public EV3UltrasonicSensor(java.lang.String portName)
port
- protected void init()
public SampleProvider getListenMode()
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.
public SampleProvider getDistanceMode()
Size and content of the sample
The sample contains one elements representing the distance (in metres) to an object in front of the sensor.
unit).
public void enable()
public void disable()
public boolean isEnabled()