public class ColorSensor extends Sensor<ShefRobot.ColorSensorAction>
ColorSensor.Mode.COLOR
, ColorSensor.Mode.RED
, ColorSensor.Mode.RGB
and ColorSensor.Mode.AMBIENT
By default the sensor starts in ColorSensor.Mode.RED
mode.
Each EV3 should contain 1 color sensor
If the sensor seems insensitive, please check that the EV3s battery is charged.
If you are switching between sensor modes without a delay, you may receive incorrect or out of range values (e.g. Calling getAmbient()
directly after getColor()
is likely to cause getAmbient()
to return a bad value. This can be fixed by waiting for around 300ms after the first call to getAmbient()
so the sensor has time to adjust.)Sensor
Modifier and Type | Class and Description |
---|---|
static class |
ColorSensor.Color
Enums used to represent the possible colours returned by the Color sensor
|
static class |
ColorSensor.FloodlightState |
static class |
ColorSensor.Mode
Modes that this sensor can be used in
|
Sensor.Port
Modifier and Type | Method and Description |
---|---|
float |
getAmbient()
Returns a value representative of the light intensity detected.
|
ColorSensor.Color |
getColor()
Returns the colour detected by the sensor as one of the
ColorSensor.Color values. |
ColorSensor.FloodlightState |
getFloodlightState()
Reads the current state of the floodlight
|
float |
getRed()
Returns the level of red reflected into the sensor
If not already in red mode, this will switch the sensor into red mode (enabling the red light).
|
Color |
getRGB()
Returns the colour detected by the sensor
~untested~
|
void |
run()
This method is for internal use, it exists due to Sensors and Motors both extending runnable.
|
void |
setFloodlightState(ColorSensor.FloodlightState newState)
Changes the state of the floodlight to a colour or off
Calls to read the sensor will change the floodlight back to the required colour
|
void |
setMode(ColorSensor.Mode newMode)
Switches the sensor between modes
|
getRawSample
public void setMode(ColorSensor.Mode newMode)
newMode
- The desired mode to switch topublic void setFloodlightState(ColorSensor.FloodlightState newState)
newState
- The desired state to switch topublic ColorSensor.FloodlightState getFloodlightState()
public ColorSensor.Color getColor()
ColorSensor.Color
values.
If not already in color mode, this will switch the sensor into color mode (enabling the white [rgb] light).ColorSensor.Color
enumpublic float getAmbient()
public float getRed()
public Color getRGB()