lejos.nxt
Class LightSensor

java.lang.Object
  extended by lejos.nxt.LightSensor
All Implemented Interfaces:
SensorConstants

public class LightSensor
extends Object
implements SensorConstants

Abstraction for a NXT light sensor. The light sensor can be calibrated to low and high values.


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_CUSTOM, 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
LightSensor(ADSensorPort port)
          Create a light sensor object attached to the specified port.
LightSensor(ADSensorPort port, boolean floodlight)
          Create a light sensor object attached to the specified port, and sets floodlighting on or off.
 
Method Summary
 void calibrateHigh()
          call this method whtn the light sensor is reading the high value - used by reaeValue
 void calibrateLow()
          call this method when the light sensor is reading the low value - used by readValue
 int getHigh()
          return the normalized value corresponding to readValue() = 100;
 int getLow()
          return the normalized value corresponding to readValue() = 0
 int readNormalizedValue()
          Read the current sensor normalized value.
 int readValue()
          Read the current sensor value.
 void setFloodlight(boolean floodlight)
          Set floodlighting on or off.
 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait
 

Constructor Detail

LightSensor

public LightSensor(ADSensorPort port)
Create a light sensor object attached to the specified port. The sensor will be set to floodlit mode, i.e. the LED will be turned on.

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

LightSensor

public LightSensor(ADSensorPort port,
                   boolean floodlight)
Create a light sensor object attached to the specified port, and sets floodlighting on or off.

Parameters:
port - port, e.g. Port.S1
floodlight - true to set floodit mode, false for ambient light.
Method Detail

setFloodlight

public void setFloodlight(boolean floodlight)
Set floodlighting on or off.

Parameters:
floodlight - true to set floodit mode, false for ambient light.

readValue

public int readValue()
Read the current sensor value. Use calibrateLow() to set the zero level, and calibrateHigh to set the 100 level.

Returns:
Value as a percentage of difference between the low and high calibration values.

readNormalizedValue

public int readNormalizedValue()
Read the current sensor normalized value. Allows more accuracy than readValue(). For LEGO sensor, values typically range from 145 (dark) to 890 (sunlight).

Returns:
Value as raw normalized (0 to 1023)

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 whtn the light sensor is reading the high value - used by reaeValue


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()
return the normalized value corresponding to readValue() = 0


getHigh

public int getHigh()
return the normalized value corresponding to readValue() = 100;