lejos.nxt.addon
Class RCXLightSensor

java.lang.Object
  extended by lejos.nxt.addon.RCXLightSensor
All Implemented Interfaces:
SensorConstants, LampLightDetector, LightDetector

public class RCXLightSensor
extends Object
implements SensorConstants, LampLightDetector

This class is used to obtain readings from a legacy RCX light sensor, using an adapter cable to connect it to the NXT brick. The light sensor can be calibrated to low and high values. Note: The RCX light sensor is not very sensitive when the floodlight is turned off: Dark is around 523, sunlight is around 634. When the floodlight is on, dark readings are around 155 and sunlight is around 713.


Field Summary
 
Fields inherited from interface lejos.nxt.SensorConstants
MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, 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
 
Constructor Summary
RCXLightSensor(LegacySensorPort port)
          Create an RCX light sensor object attached to the specified port.
 
Method Summary
 void activate()
          Deprecated. Use setFloodlight(boolean) with true instead
 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
 Colors.Color getFloodlight()
          Returns the color of the floodlight, including Color.NONE.
 int getHigh()
          The highest raw light value this sensor can return from intense bright light.
 int getLightValue()
          Returns the calibrated and normalized brightness of the white light detected.
 int getLow()
          The lowest raw light value this sensor can return in pitch black darkness.
 int getNormalizedLightValue()
          Returns the normalized value of the brightness of the white light detected, such that the lowest value is darkness and the highest value is intense bright light.
 boolean isFloodlightOn()
          Checks if the floodlight is currently on.
 void passivate()
          Deprecated. Use setFloodlight(boolean) with false instead
 int readValue()
          Deprecated. Use getLightValue() instead
 void setFloodlight(boolean floodlight)
          Turns the default LED light on or off.
 boolean setFloodlight(Colors.Color 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RCXLightSensor

public RCXLightSensor(LegacySensorPort port)
Create an RCX light sensor object attached to the specified port. The sensor will be activated, i.e. the LED will be turned on.

Parameters:
port - port, e.g. Port.S1
Method Detail

activate

public void activate()
Deprecated. Use setFloodlight(boolean) with true instead

Activates an RCX light sensor. This method should be called if you want to get accurate values from an RCX sensor. In the case of RCX light sensors, you should see the LED go on when you call this method.


passivate

public void passivate()
Deprecated. Use setFloodlight(boolean) with false instead

Passivates an RCX light sensor.


readValue

public int readValue()
Deprecated. Use getLightValue() instead

Read the current sensor value.

Returns:
Value as a percentage.

getFloodlight

public Colors.Color getFloodlight()
Description copied from interface: LampLightDetector
Returns the color of the floodlight, including Color.NONE.

Specified by:
getFloodlight in interface LampLightDetector
Returns:
An enumeration of the current color.

isFloodlightOn

public boolean isFloodlightOn()
Description copied from interface: LampLightDetector
Checks if the floodlight is currently on.

Specified by:
isFloodlightOn in interface LampLightDetector
Returns:
true if on, false if off.

setFloodlight

public void setFloodlight(boolean floodlight)
Description copied from interface: LampLightDetector
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:
setFloodlight in interface LampLightDetector
Parameters:
floodlight - true to turn on lamp, false for off (ambient light only).

setFloodlight

public boolean setFloodlight(Colors.Color color)
Description copied from interface: LampLightDetector
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.

Specified by:
setFloodlight in interface LampLightDetector
Parameters:
color - Use lejos.robotics.Color enumeration constant to control lamp colors.
Returns:
True if lamp changed, false if lamp color doesn't exist for this sensor.

getLightValue

public int getLightValue()
Description copied from interface: LightDetector
Returns the calibrated and normalized brightness of the white light detected.

Specified by:
getLightValue in interface LightDetector
Returns:
A brightness value between 0 and 100%, with 0 = darkness and 100 = intense sunlight

getNormalizedLightValue

public int getNormalizedLightValue()
Description copied from interface: LightDetector
Returns the normalized value of the brightness of the white light detected, such that the lowest value is darkness and the highest value is intense bright light.

Specified by:
getNormalizedLightValue in interface LightDetector
Returns:
A raw value, between getLow() and getHigh(). Usually between 0 and 1023 but can be anything depending on hardware.

calibrateLow

public void calibrateLow()
call this method when the light sensor is reading the low value - used by readValue


calibrateHigh

public void calibrateHigh()
call this method when the light sensor is reading the high value - used by readValue


setLow

public void setLow(int low)
set the normalized value corresponding to readValue() = 0

Parameters:
low - the low value

setHigh

public void setHigh(int high)
set the normalized value corresponding to readValue() = 100;

Parameters:
high - the high value

getLow

public int getLow()
Description copied from interface: LightDetector
The lowest raw light value this sensor can return in pitch black darkness.

Specified by:
getLow in interface LightDetector
Returns:

getHigh

public int getHigh()
Description copied from interface: LightDetector
The highest raw light value this sensor can return from intense bright light.

Specified by:
getHigh in interface LightDetector
Returns: