ch.aplu.nxt
Class LightSensor

java.lang.Object
  extended by ch.aplu.nxt.Part
      extended by ch.aplu.nxt.Sensor
          extended by ch.aplu.nxt.LightSensor
All Implemented Interfaces:
SharedConstants

public class LightSensor
extends Sensor
implements SharedConstants

Class that represents a light sensor.


Field Summary
 
Fields inherited from interface ch.aplu.nxt.SharedConstants
ABOUT, ACCELEROMETERPOLLDELAY, ANGLE, ANGLESTEPSMODE, AXELENGTH, BOOLEANMODE, BOOT, BRAKE, BRAKEDELAY, CELSIUSMODE, CLOSE, COLORPOLLDELAY, COMPASSPOLLDELAY, CRAWLERROTATIONFACTOR, CRAWLERROTATIONSPEED, CRAWLERSPEED, CRAWLERSTEPFACTOR, CUSTOM, DEBUG_LEVEL_HIGH, DEBUG_LEVEL_LOW, DEBUG_LEVEL_MEDIUM, DEBUG_LEVEL_OFF, DEBUGLEVEL, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GEARSPEED, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, GYROPOLLDELAY, HIGH_SPEED_BUFFER, INFRAREDSEEKERPOLLDELAY, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LIGHTPOLLDELAY, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTIONDETECTORPOLLDELAY, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, MOTORSPEED, MOTORSPEEDFACTOR, MOTORSPEEDMULTIPLIER, NO_OF_SENSOR_TYPES, NO_SENSOR, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, PROTOTYPEPOLLDELAY, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, RFIDPOLLDELAY, SENSOREVENTDELAY, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, SOUNDPOLLDELAY, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TITLE, TITLEMP, TOUCHPOLLDELAY, TRANSITIONCNTMODE, TURTLEROTATIONFACTOR, TURTLEROTATIONSPEED, TURTLESPEED, TURTLESTEPFACTOR, ULTRASONICPOLLDELAY, VERSION, WRITE
 
Constructor Summary
LightSensor()
          Creates a sensor instance connected to port S1.
LightSensor(SensorPort port)
          Creates a sensor instance connected to the given port.
 
Method Summary
 void activate(boolean enable)
          Turns on/off the LED used for reflecting light back into the sensor.
 void addLightListener(LightListener lightListener)
          Registers the given light listener with default trigger level 500.
 void addLightListener(LightListener lightListener, int triggerLevel)
          Registers the given light listener for the given trigger level.
 lejos.nxt.SensorPort getLejosPort()
          Returns the reference of the the underlying lejos.nxt.SensorPort.
 lejos.nxt.LightSensor getLejosSensor()
          Returns the reference of the the underlying lejos.nxt.LightSensor.
 int getValue()
          Polls the sensor.
 int setTriggerLevel(int triggerLevel)
          Sets a new trigger level and returns the previous one.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LightSensor

public LightSensor(SensorPort port)
Creates a sensor instance connected to the given port.

Parameters:
port - the port where the sensor is plugged-in

LightSensor

public LightSensor()
Creates a sensor instance connected to port S1.

Method Detail

addLightListener

public void addLightListener(LightListener lightListener,
                             int triggerLevel)
Registers the given light listener for the given trigger level.

Parameters:
lightListener - the LightListener to become registered.
triggerLevel - the trigger level where the callback is triggered

addLightListener

public void addLightListener(LightListener lightListener)
Registers the given light listener with default trigger level 500.

Parameters:
lightListener - the LightListener to become registered.

setTriggerLevel

public int setTriggerLevel(int triggerLevel)
Sets a new trigger level and returns the previous one.

Parameters:
triggerLevel - the new trigger level
Returns:
the previous trigger level

activate

public void activate(boolean enable)
Turns on/off the LED used for reflecting light back into the sensor.

Parameters:
enable - if true, turn the LED on, otherwise turn it off

getValue

public int getValue()
Polls the sensor.

Returns:
the current value the sensor reported: 0 (dark) .. 1023 (bright)

getLejosSensor

public lejos.nxt.LightSensor getLejosSensor()
Returns the reference of the the underlying lejos.nxt.LightSensor.

Returns:
the reference of the LightSensor

getLejosPort

public lejos.nxt.SensorPort getLejosPort()
Returns the reference of the the underlying lejos.nxt.SensorPort.

Returns:
the reference of the SensorPort