Package lejos.hardware.sensor
Class NXTColorSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.AnalogSensor
-
- lejos.hardware.sensor.NXTColorSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorConstants,SensorMode,SensorModes,ColorIdentifier,LampController,SampleProvider
public class NXTColorSensor extends AnalogSensor implements SensorConstants, LampController, ColorIdentifier
LEGO NXT Color Sensor
allows the reading of raw color values. The sensor has a tri-color LED and this can be set to output red/green/blue or off. It also has a full mode in which four samples are read (off/red/green/blue) very quickly. These samples can then be combined using the calibration data provided by the device to determine the "LEGO" color currently being viewed.Supported modes Mode name Description unit(s) Getter Color ID Measures the color ID Color ID getColorIDMode()Red Measures the light value when illuminated with a red light source. N/A, normalized getRedMode()Green Measures the light value when illuminated with a green light source. N/A, normalized getGreenMode()Blue Measures the light value when illuminated with a blue light source. N/A, normalized getBlueMode()RGB Measures the light value when illuminated with a white light source. N/A, normalized getRGBMode()Ambient Measures the light value of ambient light. N/A, normalized getAmbientMode()See The leJOS sensor framework See
leJOS conventions for SampleProviders- Author:
- Andy
-
-
Field Summary
Fields Modifier and Type Field Description protected static int[]colorMapprotected 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 NXTColorSensor(AnalogPort port)Create a new Color Sensor instance and bind it to a port.NXTColorSensor(Port port)Create a new Color Sensor instance and bind it to a 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.SensorModegetBlueMode()get a sample provider the returns the light value when illuminated with a Blue light source.intgetColorID()Read the current color and return an enumeration constant.SensorModegetColorIDMode()get a sample provider in color ID modeintgetFloodlight()Returns the color of the floodlight, including Color.NONE.SensorModegetGreenMode()get a sample provider the returns the light value when illuminated with a Green light source.SensorModegetRedMode()get a sample provider the returns the light value when illuminated with a Red light source.SensorModegetRGBMode()get a sample provider the returns the light values (RGB + ambient) when illuminated by a white light source.protected voidinit()booleanisFloodlightOn()Checks if the floodlight is currently on.protected voidreadFull()protected voidreadRaw()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
-
colorMap
protected static int[] colorMap
-
-
Constructor Detail
-
NXTColorSensor
public NXTColorSensor(AnalogPort port)
Create a new Color Sensor instance and bind it to a port.- Parameters:
port- Port to use for the sensor.
-
NXTColorSensor
public NXTColorSensor(Port port)
Create a new Color Sensor instance and bind it to a port.- Parameters:
port- Port to use for the sensor.
-
-
Method Detail
-
init
protected void init()
-
getColorIDMode
public SensorMode getColorIDMode()
get a sample provider in color ID mode- Returns:
- the sample provider
-
getRedMode
public SensorMode getRedMode()
get a sample provider the returns the light value when illuminated with a Red light source.- Returns:
- the sample provider
-
getGreenMode
public SensorMode getGreenMode()
get a sample provider the returns the light value when illuminated with a Green light source.- Returns:
- the sample provider
-
getBlueMode
public SensorMode getBlueMode()
get a sample provider the returns the light value when illuminated with a Blue light source.- Returns:
- the sample provider
-
getRGBMode
public SensorMode getRGBMode()
get a sample provider the returns the light values (RGB + ambient) when illuminated by a white 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
-
readRaw
protected void readRaw()
-
readFull
protected void readFull()
-
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).
-
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.
-
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.
-
getColorID
public int getColorID()
Read the current color and return an enumeration constant. This is usually only accurate at a distance of about 1 cm.- Specified by:
getColorIDin interfaceColorIdentifier- Returns:
- The color id under the sensor.
-
-