Package lejos.hardware.sensor
Class NXTLightSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.AnalogSensor
-
- lejos.hardware.sensor.NXTLightSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorConstants,SensorMode,SensorModes,LampController,SampleProvider
public class NXTLightSensor extends AnalogSensor implements LampController, SensorConstants
LEGO NXT light Sensor
The NXT light sensor measures light levels of reflected or ambient light.Supported modes Mode name Description unit(s) Getter Red Measures the light value when illuminated with a red light source. N/A, normalized getRedMode()Ambient Measures the light value of ambient light. N/A, normalized getAmbientMode()
-
-
Field Summary
Fields Modifier and Type Field Description protected static longSWITCH_DELAY-
Fields inherited from class lejos.hardware.sensor.AnalogSensor
currentType, port
-
Fields inherited from class lejos.hardware.sensor.BaseSensor
currentMode, modes
-
Fields inherited from interface lejos.hardware.sensor.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, BROWN, GREEN, GREEN_INDEX, MAX_TYPE, MIN_TYPE, MODE_RAW, NXT_ADC_RES, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HIGHSPEED, TYPE_HIGHSPEED_9V, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
-
-
Constructor Summary
Constructors Constructor Description NXTLightSensor(AnalogPort port)Create a light sensor object attached to the specified port.NXTLightSensor(Port port)Create a light sensor object attached to the specified port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SensorModegetAmbientMode()get a sample provider the returns the light value when illuminated without a light source.intgetFloodlight()Returns the color of the floodlight, including Color.NONE.SensorModegetRedMode()get a sample provider the returns the light value when illuminated with a Red light source.protected voidinit()booleanisFloodlightOn()Checks if the floodlight is currently on.voidsetFloodlight(boolean floodlight)Turns the default LED light on or off.booleansetFloodlight(int color)Used to turn on or off the floodlight by color.-
Methods inherited from class lejos.hardware.sensor.AnalogSensor
normalize, NXTRawIntValue, NXTRawValue, switchType
-
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
-
-
-
-
Field Detail
-
SWITCH_DELAY
protected static final long SWITCH_DELAY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NXTLightSensor
public NXTLightSensor(AnalogPort port)
Create a light sensor object attached to the specified port. The sensor will be set to floodlight mode, i.e. the LED will be turned on.- Parameters:
port- port, e.g. Port.S1
-
NXTLightSensor
public NXTLightSensor(Port port)
Create a light sensor object attached to the specified port. The sensor will be set to floodlight mode, i.e. the LED will be turned on.- Parameters:
port- port, e.g. Port.S1
-
-
Method Detail
-
init
protected void init()
-
setFloodlight
public void setFloodlight(boolean floodlight)
Description copied from interface:LampControllerTurns the default LED light on or off. If the sensor has more than one lamp color, this will control the red LED.- Specified by:
setFloodlightin interfaceLampController- Parameters:
floodlight- true to turn on lamp, false for off (ambient light only).
-
setFloodlight
public boolean setFloodlight(int color)
Description copied from interface:LampControllerUsed to turn on or off the floodlight by color. If the sensor has multiple light colors, you can control which color is turned on or off. If the color does not exist, it does nothing and returns false. You can turn the floodlight off by using Color.NONE.- Specified by:
setFloodlightin interfaceLampController- Parameters:
color- UseColorenumeration constant to control lamp colors.- Returns:
- True if lamp changed, false if lamp color doesn't exist for this sensor.
-
getFloodlight
public int getFloodlight()
Description copied from interface:LampControllerReturns the color of the floodlight, including Color.NONE.- Specified by:
getFloodlightin interfaceLampController- Returns:
- An enumeration of the current color.
-
isFloodlightOn
public boolean isFloodlightOn()
Description copied from interface:LampControllerChecks if the floodlight is currently on.- Specified by:
isFloodlightOnin interfaceLampController- Returns:
- true if on, false if off.
-
getRedMode
public SensorMode getRedMode()
get a sample provider the returns the light value when illuminated with a Red light source.- Returns:
- the sample provider
-
getAmbientMode
public SensorMode getAmbientMode()
get a sample provider the returns the light value when illuminated without a light source.- Returns:
- the sample provider
-
-