DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


built_in:nxt_readtouchsensor

Differences

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

Link to this comparison view

built_in:nxt_readtouchsensor [2015/03/09 16:14] (current)
octazid created
Line 1: Line 1:
 +====== 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).
 +<​code>​touch = nxt.ReadTouchSensor( input );</​code>​
 +
 +====Example - Read touch sensor on port 2====
 +<code javascript>​
 +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 );
 +  }
 +}
 +</​code>​
built_in/nxt_readtouchsensor.txt ยท Last modified: 2015/03/09 16:14 by octazid