lejos.nxt
Class SensorPort.ColorSensorReader

java.lang.Object
  extended by lejos.nxt.SensorPort.SensorReader
      extended by lejos.nxt.SensorPort.ColorSensorReader
Enclosing class:
SensorPort

protected class SensorPort.ColorSensorReader
extends SensorPort.SensorReader

Lego Color Sensor driver. This driver provides access to the Lego Color sensor. It allows the reading 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.

Author:
andy

Constructor Summary
SensorPort.ColorSensorReader()
          Create a new Color Sensor instance and bind it to a port.
 
Method Summary
 int readRawValue()
          Return a single raw value from the device.
 int readRawValues(int[] vals)
          When in full color mode this returns all four raw color values from the device by doing four very quick reads and flashing all colors.
 int readValue()
          Return a single processed value.
 int readValues(int[] vals)
          Return a set of calibrated data.
 void reset()
          Reset the sensor.
 void setType(int type)
          Change the type of the sensor
 
Methods inherited from class lejos.nxt.SensorPort.SensorReader
setMode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SensorPort.ColorSensorReader

public SensorPort.ColorSensorReader()
Create a new Color Sensor instance and bind it to a port.

Method Detail

setType

public void setType(int type)
Change the type of the sensor

Overrides:
setType in class SensorPort.SensorReader
Parameters:
type - new sensor type.

reset

public void reset()
Reset the sensor.

Overrides:
reset in class SensorPort.SensorReader

readRawValue

public int readRawValue()
Return a single raw value from the device. When in single color mode this returns the raw sensor reading. Values range from 0 to 1023 but usually don't get over 600.

Overrides:
readRawValue in class SensorPort.SensorReader
Returns:
the raw value or < 0 if there is an error.

readRawValues

public int readRawValues(int[] vals)
When in full color mode this returns all four raw color values from the device by doing four very quick reads and flashing all colors. The raw values theoretically range from 0 to 1023 but in practice they usually do not go higher than 600. You can access the index of each color using RGB_RED, RGB_GREEN, RGB_BLUE and RGB_BLANK. e.g. to retrieve the Blue value: vals[ColorSensor.RGB_BLUE]

Overrides:
readRawValues in class SensorPort.SensorReader
Parameters:
vals - array of four color values.
Returns:
< 0 if there is an error the number of values if ok

readValues

public int readValues(int[] vals)
Return a set of calibrated data. If in single color mode the returned data is a simple percentage. If in full color mode the data is a set of calibrated red/blue/green/blank readings that range from 0 to 255. You can access the index of each color using RED_INDEX, GREEN_INDEX, BLUE_INDEX and BLANK_INDEX. e.g. to retrieve the Blue value: vals[ColorSensor.BLUE_INDEX]

Overrides:
readValues in class SensorPort.SensorReader
Parameters:
vals - 4 element array for the results
Returns:
< 0 of error, the number of values if ok

readValue

public int readValue()
Return a single processed value. If in single color mode this returns a single reading as a percentage. If in full color mode it returns a Lego color value that identifies the color of the object in view.

Overrides:
readValue in class SensorPort.SensorReader
Returns:
processed color value.