Table of Contents

ReadLightSensor

The ReadLightSensor function reads the intensity of the light currently being 'seen' by the NXT light sensor.

The input parameter should be an NXT input port number between 1 and 4 (which the light sensor is plugged into).

The active parameter should be set to true if you want the white light to be turned on during sensing and false if the light is not required.

The returned value will be a light level value between 0 and 100.

level = nxt.ReadLightSensor( input, active );

Example - Sense light level on port 3

function OnStart()
{
  nxt = app.CreateNxt();
  app.SetMenu( "Connect,Light Level" );
}
 
function OnMenu( name )
{
  if( name=="Connect" )
    nxt.ShowDevices();
 
  else if( name=="Light Level" )
  {
    level = nxt.ReadLightSensor( 3, false );
    app.ShowPopup( level );
  }
}