DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


built_in:nxt_tocolorname

Differences

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

Link to this comparison view

built_in:nxt_tocolorname [2015/03/21 18:34] (current)
madlyr created
Line 1: Line 1:
 +====== ToColorName ======
  
 +The **ToColorName** returns string with one of the six colors: black, blue, green, yellow, red, white converted from **colorNum** parameter.
 +You can use the ToColorName function to convert value obtained from color sensor by method [[nxt_readcolorsensor|ReadColorSensor]] with mode set to ColorDetect.
 +
 +If the mode **ColorDetect** is chosen, then the returned values will be a number between 1 and 6 which represent the following colors: black, blue, green, yellow, red, white.
 +
 +<​code>​txtColor = nxt.ToColorName( colorNum );</​code>​
 + 
 +====Example - Sense color on port 3====
 +<code javascript>​
 +function OnStart()
 +{
 +  nxt = app.CreateNxt();​
 +  app.SetMenu( "​Connect,​Sense Color" );
 +}
 +
 +function OnMenu( name )
 +{
 +  if( name=="​Connect"​ )
 +    nxt.ShowDevices();​
 +
 +  else if( name=="​Sense Color" )
 +  {
 +    clr = nxt.ReadColorSensor( 3, "​ColorDetect"​ );
 +    app.ShowPopup( nxt.ToColorName( clr ) );
 +  }
 +}
 +</​code>​
built_in/nxt_tocolorname.txt ยท Last modified: 2015/03/21 18:34 by madlyr