DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


built_in:nxt_readdistancesensor

Differences

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

Link to this comparison view

built_in:nxt_readdistancesensor [2015/03/09 16:08] (current)
octazid created
Line 1: Line 1:
 +====== ReadDistanceSensor ======
  
 +The **ReadDistanceSensor** function reads the distance measured by the ultrasonic sensor in centimeters.
 +
 +The **input** parameter should be an NXT input port number between 1 and 4 (which the ultrasonic sensor is plugged into).
 +<​code>​dist = nxt.ReadDistanceSensor( input );</​code>​
 +
 +
 +====Example - Read distance sensor on port 4====
 +<code javascript>​
 +function OnStart()
 +{
 +  nxt = app.CreateNxt();​
 +  app.SetMenu( "​Connect,​Distance"​ );
 +}
 +
 +function OnMenu( name )
 +{
 +  if( name=="​Connect"​ )
 +    nxt.ShowDevices();​
 +
 +  else if( name=="​Distance"​ )
 +  {
 +    dist = nxt.ReadDistanceSensor( 4 );
 +    app.ShowPopup( dist + " cm" );
 +  }
 +}
 +</​code>​
built_in/nxt_readdistancesensor.txt ยท Last modified: 2015/03/09 16:08 by octazid