public class ColorSensor extends Sensor
Modifier and Type | Field and Description |
---|---|
static int[][] |
colorCubes
Color cubes for detecting color labels.
6 user adaptable int arrays with red_min, red_max, green_min, green_max, blue_min, blue_max
for the colors black, blue, green, yellow, red, white with indices 0, 1, 2, 3, 5, 6.
|
Constructor and Description |
---|
ColorSensor()
Creates a sensor instance connected to port S1.
|
ColorSensor(SensorPort port)
Creates a sensor instance connected to the given port.
|
Modifier and Type | Method and Description |
---|---|
java.awt.Color |
getColor()
Polls the sensor.
|
int |
getColorID()
Returns a integer number ID for the current color reading.
|
int |
getColorInt()
Polls the sensor.
|
ColorLabel |
getColorLabel()
Returns one of the enums of ColorLabel.
|
java.lang.String |
getColorStr()
Returns the name of the enums of ColorLabel.
|
static boolean |
inColorCube(java.awt.Color color,
int[] colorCube)
Checks if given color lies within given color cube.
|
void |
setFloodlight(int colorValue)
Turns the red, green or blue LED on or all off.
|
public static int[][] colorCubes
ColorSensor.colorCubes[1] = new int[]{10, 20, 30, 40, 50, 60};
public ColorSensor(SensorPort port)
port
- the port where the sensor is plugged-inpublic ColorSensor()
public java.awt.Color getColor()
public int getColorInt()
public int getColorID()
public ColorLabel getColorLabel()
public java.lang.String getColorStr()
public static boolean inColorCube(java.awt.Color color, int[] colorCube)
color
- the color to checkcolorCube
- an integer array of 6 boundary values in the order:
red_min, red_max, green_min, green_max, blue_min, blue_maxpublic void setFloodlight(int colorValue)
colorValue
- 0: red, 1: green, 2: blue, -1: all off