Class EV3ColorSensor
- java.lang.Object
-
- lejos.hardware.Device
-
- lejos.hardware.sensor.BaseSensor
-
- lejos.hardware.sensor.UARTSensor
-
- lejos.hardware.sensor.EV3ColorSensor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,SensorMode,SensorModes,ColorIdentifier,LampController,SampleProvider
public class EV3ColorSensor extends UARTSensor implements LampController, ColorIdentifier
EV3 color sensor
The digital EV3 Color Sensor distinguishes between eight different colors. It also serves as a light sensor by detecting light intensities.Supported modes Mode name Description unit(s) Getter Color ID Measures the color ID of a surface Color ID getColorIDMode()Red Measures the intensity of a reflected red light N/A, Normalized to (0-1) getRedMode()RGB Measures the RGB color of a surface N/A, Normalized to (0-1) getRGBMode()Ambient Measures the ambient light level N/A, Normalized to (0-1) getAmbientMode()Sensor configuration
The flood light of the sensor can be put on or off using the setFloodlight methods.See Sensor Product page See The leJOS sensor framework See
leJOS conventions for SampleProviders- Author:
- Andy
-
-
Field Summary
Fields Modifier and Type Field Description protected static intCOL_AMBIENTprotected static intCOL_CALprotected static intCOL_COLORprotected static intCOL_REFLECTprotected static intCOL_REFRAWprotected static intCOL_RESETprotected static intCOL_RGBRAWprotected static int[]colorMapprotected static int[]lightColorprotected short[]rawprotected static intSWITCH_DELAY-
Fields inherited from class lejos.hardware.sensor.UARTSensor
currentMode, port
-
Fields inherited from class lejos.hardware.sensor.BaseSensor
modes
-
-
Constructor Summary
Constructors Constructor Description EV3ColorSensor(Port port)EV3ColorSensor(UARTPort port)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SensorModegetAmbientMode()EV3 color sensor, Ambient mode
Measures the level of ambient light while the sensors lights are off.intgetColorID()Return an enumerated constant that indicates the color detected.SensorModegetColorIDMode()EV3 color sensor, Color ID mode
Measures the color ID of a surface.intgetFloodlight()Returns the color of the floodlight, including Color.NONE.SensorModegetRedMode()EV3 color sensor, Red mode
Measures the level of reflected light from the sensors RED LED.SensorModegetRGBMode()EV3 color sensor, RGB mode
Measures the level of red, green and blue light when illuminated by a white light source..protected voidinitModes()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.UARTSensor
switchMode
-
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
-
colorMap
protected static int[] colorMap
-
SWITCH_DELAY
protected static final int SWITCH_DELAY
- See Also:
- Constant Field Values
-
COL_RESET
protected static final int COL_RESET
- See Also:
- Constant Field Values
-
COL_REFLECT
protected static final int COL_REFLECT
- See Also:
- Constant Field Values
-
COL_AMBIENT
protected static final int COL_AMBIENT
- See Also:
- Constant Field Values
-
COL_COLOR
protected static final int COL_COLOR
- See Also:
- Constant Field Values
-
COL_REFRAW
protected static final int COL_REFRAW
- See Also:
- Constant Field Values
-
COL_RGBRAW
protected static final int COL_RGBRAW
- See Also:
- Constant Field Values
-
COL_CAL
protected static final int COL_CAL
- See Also:
- Constant Field Values
-
lightColor
protected static final int[] lightColor
-
raw
protected short[] raw
-
-
Method Detail
-
initModes
protected void initModes()
-
getColorID
public int getColorID()
Return an enumerated constant that indicates the color detected. e.g. Color.BLUE- Specified by:
getColorIDin interfaceColorIdentifier- Returns:
- An integer from the Color constants, such as Color.BLUE
-
setFloodlight
public void setFloodlight(boolean floodlight)
Turns 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).
-
isFloodlightOn
public boolean isFloodlightOn()
Checks if the floodlight is currently on.- Specified by:
isFloodlightOnin interfaceLampController- Returns:
- true if on, false if off.
-
getFloodlight
public int getFloodlight()
Returns the color of the floodlight, including Color.NONE.- Specified by:
getFloodlightin interfaceLampController- Returns:
- An enumeration of the current color.
-
setFloodlight
public boolean setFloodlight(int color)
Used 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.
-
getColorIDMode
public SensorMode getColorIDMode()
EV3 color sensor, Color ID mode
Measures the color ID of a surface. The sensor can identify 8 unique colors (NONE, BLACK, BLUE, GREEN, YELLOW, RED, WHITE, BROWN).Size and content of the sample
The sample contains one element containing the ID (0-7) of the detected color.- Returns:
- A sampleProvider
See
leJOS conventions for SampleProviders
-
getRedMode
public SensorMode getRedMode()
EV3 color sensor, Red mode
Measures the level of reflected light from the sensors RED LED.Size and content of the sample
The sample contains one element containing the intensity level (Normalized between 0 and 1) of reflected light.- Returns:
- A sampleProvider
See
leJOS conventions for SampleProviders
-
getAmbientMode
public SensorMode getAmbientMode()
EV3 color sensor, Ambient mode
Measures the level of ambient light while the sensors lights are off.Size and content of the sample
The sample contains one element containing the intensity level (Normalized between 0 and 1) of ambient light.- Returns:
- A sampleProvider
See
leJOS conventions for SampleProviders
-
getRGBMode
public SensorMode getRGBMode()
EV3 color sensor, RGB mode
Measures the level of red, green and blue light when illuminated by a white light source..Size and content of the sample
The sample contains 3 elements containing the intensity level (Normalized between 0 and 1) of red, green and blue light respectivily.- Returns:
- A sampleProvider
See
leJOS conventions for SampleProviders
-
-