public class LightSensor extends Part
Constructor and Description |
---|
LightSensor(SensorPort port)
Creates a sensor instance pointing downwards connected to the given port.
|
LightSensor(SensorPort port,
boolean upwards)
Creates a sensor instance connected to the given port.
|
Modifier and Type | Method and Description |
---|---|
void |
activate(boolean enable)
Turns on/off the LED used for reflecting light back into the sensor.
|
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.
|
SensorPort |
getPort()
Returns the port of the sensor.
|
int |
getValue()
For sensor ports 1, 2, 3, 4: returns the brightness of the background
at the current location.
|
int |
setTriggerLevel(int triggerLevel)
Sets a new triggerLevel and returns the previous one.
|
public LightSensor(SensorPort port)
port
- the port where the sensor is plugged-inpublic LightSensor(SensorPort port, boolean upwards)
port
- the port where the sensor is plugged-inupwards
- if true, the sensor is pointing upwards; otherwise pointing downwardspublic 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 void activate(boolean enable)
enable
- if true, turn the LED on, otherwise turn it offpublic SensorPort getPort()