DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


built_in:nxt_readlightsensor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

built_in:nxt_readlightsensor [2015/03/09 16:12] (current)
octazid created
Line 1: Line 1:
 +====== 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.
 +<​code>​level = nxt.ReadLightSensor( input, active );</​code>​
 +
 +====Example - Sense light level on port 3====
 +<code javascript>​
 +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 );
 +  }
 +}
 +</​code>​
built_in/nxt_readlightsensor.txt ยท Last modified: 2015/03/09 16:12 by octazid