Table of Contents

ReadTouchSensor

The ReadTouchSensor function reads the state of the NXT touch sensor, which will be true if the switch is currently pushed in and false otherwise.

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

touch = nxt.ReadTouchSensor( input );

Example - Read touch sensor on port 2

function OnStart()
{
  nxt = app.CreateNxt();
  app.SetMenu( "Connect,Touch Sense" );
}
 
function OnMenu( name )
{
  if( name=="Connect" )
    nxt.ShowDevices();
 
  else if( name=="Touch Sense" )
  {
    touch = nxt.ReadTouchSensor( 2 );
    app.ShowPopup( touch );
  }
}