|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object lejos.nxt.ColorSensor
public class ColorSensor
LEGO Color Sensor driver. This driver provides access to the LEGO Color sensor. It allows the reading of raw and processed 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.
Nested Class Summary | |
---|---|
static class |
ColorSensor.Color
Extended color class, that includes the background reading at the time that the other readings were made. |
Field Summary | |
---|---|
protected static int[] |
colorMap
|
protected SensorPort |
port
|
protected int |
type
|
Fields inherited from interface lejos.nxt.SensorConstants |
---|
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, 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 | |
---|---|
ColorSensor(SensorPort port)
Create a new Color Sensor instance and bind it to a port. |
|
ColorSensor(SensorPort port,
int color)
Create a new Color Sensor instance and bind it to a port. |
Method Summary | |
---|---|
void |
calibrateHigh()
call this method when the light sensor is reading the high value - used by readValue |
void |
calibrateLow()
call this method when the light sensor is reading the low value - used by readValue |
ColorSensor.Color |
getColor()
Return a Color Object that contains the calibrated color readings. |
int |
getColorID()
Read the current color and return an enumeration constant. |
int |
getFloodlight()
Returns the color of the floodlight, including Color.NONE. |
int |
getHigh()
return the normalized value corresponding to readValue() = 100; |
int |
getLightValue()
Return the calibrated light reading. |
int |
getLow()
return the normalized value corresponding to readValue() = 0 |
int |
getNormalizedLightValue()
Return the normalized light level. |
ColorSensor.Color |
getRawColor()
Return a Color Object that contains the raw color readings. |
int |
getRawLightValue()
Return the Raw light reading. |
boolean |
isFloodlightOn()
Checks if the floodlight is currently on. |
void |
setFloodlight(boolean floodlight)
Turns the default LED light on or off. |
boolean |
setFloodlight(int color)
Used to turn on or off the floodlight by color. |
void |
setHigh(int high)
set the normalized value corresponding to readValue() = 100; |
void |
setLow(int low)
set the normalized value corresponding to readValue() = 0 |
protected void |
setType(int type)
Change the type of the sensor |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static int[] colorMap
protected SensorPort port
protected int type
Constructor Detail |
---|
public ColorSensor(SensorPort port)
port
- Port to use for the sensor.public ColorSensor(SensorPort port, int color)
port
- Port to use for the sensor.color
- The floodlight color.Method Detail |
---|
protected void setType(int type)
type
- new sensor type.public int getLightValue()
getLightValue
in interface LightDetector
public int getNormalizedLightValue()
getNormalizedLightValue
in interface LightDetector
public int getRawLightValue()
public void setFloodlight(boolean floodlight)
LampLightDetector
setFloodlight
in interface LampLightDetector
floodlight
- true to turn on lamp, false for off (ambient light only).public ColorSensor.Color getColor()
getColor
in interface ColorDetector
public ColorSensor.Color getRawColor()
public int getFloodlight()
LampLightDetector
getFloodlight
in interface LampLightDetector
public boolean isFloodlightOn()
LampLightDetector
isFloodlightOn
in interface LampLightDetector
public boolean setFloodlight(int color)
LampLightDetector
setFloodlight
in interface LampLightDetector
color
- Use Color
enumeration constant to control lamp colors.
public void calibrateLow()
public void calibrateHigh()
public void setLow(int low)
low
- the low valuepublic void setHigh(int high)
high
- the high valuepublic int getLow()
getLow
in interface LightDetector
public int getHigh()
getHigh
in interface LightDetector
public int getColorID()
getColorID
in interface ColorDetector
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |