public class LightSensor extends Part
Modifier and Type | Field and Description |
---|---|
static int |
LS_FRONT_LEFT
Constant for id of front left sensor
|
static int |
LS_FRONT_RIGHT
Constant for id of front right sensor
|
static int |
LS_REAR_LEFT
Constant for id of front left sensor
|
static int |
LS_REAR_RIGHT
Constant for id of front right sensor
|
Constructor and Description |
---|
LightSensor(int id)
Creates a motor instance with given id.
|
Modifier and Type | Method and Description |
---|---|
void |
addLightListener(LightListener lightListener)
Registers the given LightListener with default trigger triggerLevel 500.
|
void |
addLightListener(LightListener listener,
int triggerLevel)
Registers the given LightListener to detect crossing the given trigger triggerLevel.
|
int |
getId()
Returns the if of the sensor.
|
int |
getValue()
Returns the brightness of all torches at the current location;
0, if the sensor is inside a shadow region.
|
int |
setTriggerLevel(int triggerLevel)
Sets a new triggerLevel and returns the previous one.
|
public static int LS_FRONT_LEFT
public static int LS_FRONT_RIGHT
public static int LS_REAR_LEFT
public static int LS_REAR_RIGHT
public LightSensor(int id)
id
- 0 for front left, 1 for front right,
2 for rear left, 3 for rear rightpublic void addLightListener(LightListener listener, int triggerLevel)
listener
- the LightListener to registertriggerLevel
- the light value used as trigger levelpublic void addLightListener(LightListener lightListener)
lightListener
- the LightListener to registerpublic int setTriggerLevel(int triggerLevel)
triggerLevel
- the new trigger triggerLevelpublic int getValue()
public int getId()