public class UltrasonicSensor extends Part
Constructor and Description |
---|
UltrasonicSensor(SensorPort port)
The port selection determines the position of the sensor and
the direction of the beam axis.
|
Modifier and Type | Method and Description |
---|---|
void |
addUltrasonicListener(UltrasonicListener listener)
Registers the given UltrasonicListener with default trigger triggerLevel 100.
|
void |
addUltrasonicListener(UltrasonicListener listener,
int triggerLevel)
Registers the given UltrasonicListener to detect crossing the given trigger triggerLevel.
|
void |
eraseBeamArea()
Erases the beam area (if it is currently shown).
|
int |
getDistance()
Returns the distance to the nearest target object.
|
SensorPort |
getPort()
Returns the port of the sensor.
|
void |
setBeamAreaColor(java.awt.Color color)
Sets the color of the beam area (two sector border lines and axis).
|
void |
setMeshTriangleColor(java.awt.Color color)
Sets the color of the triangle mesh lines.
|
void |
setProximityCircleColor(java.awt.Color color)
Sets the color of the circle with center at sensor location and radius
equals to the current distance value.
|
int |
setTriggerLevel(int triggerLevel)
Sets a new trigger level and returns the previous one.
|
public UltrasonicSensor(SensorPort port)
port
- the port where the sensor is plugged-inpublic void addUltrasonicListener(UltrasonicListener listener, int triggerLevel)
listener
- the UltrasonicListener to registertriggerLevel
- the distance value used as trigger levelpublic void addUltrasonicListener(UltrasonicListener listener)
listener
- the UltrasonicListener to registerpublic int setTriggerLevel(int triggerLevel)
triggerLevel
- the new trigger levelpublic int getDistance()
public SensorPort getPort()
public void setMeshTriangleColor(java.awt.Color color)
color
- the color of the mesh; if null, the mesh is not shown (default)public void setBeamAreaColor(java.awt.Color color)
color
- the color of the beam area; if null, the beam lines are not shown (default)public void eraseBeamArea()
public void setProximityCircleColor(java.awt.Color color)
color
- the color of the circle; if null, the circle is not shown (default)