This shows you the differences between two versions of the page.
built_in:nxt_readcolorsensor [2015/03/09 16:05] octazid created |
built_in:nxt_readcolorsensor [2015/03/22 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== ReadColorSensor ====== | ||
- | The **ReadColorSensor** function reads the color currently being ' | ||
- | |||
- | The **input** parameter should be an NXT input port number between 1 and 4 (which the color sensor is plugged into). | ||
- | |||
- | The **mode** parameter should be one of the following values: | ||
- | * " | ||
- | * " | ||
- | * " | ||
- | * " | ||
- | * " | ||
- | |||
- | 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. | ||
- | |||
- | You can use the **ToColorName** function to convert from these six values to a color name | ||
- | |||
- | If any of the other modes are chosen, then the result will be a color intensity value between 0 and 1023. | ||
- | < | ||
- | |||
- | ====Example - Sense color on port 3==== | ||
- | <code javascript> | ||
- | function OnStart() | ||
- | { | ||
- | nxt = app.CreateNxt(); | ||
- | app.SetMenu( " | ||
- | } | ||
- | |||
- | function OnMenu( name ) | ||
- | { | ||
- | if( name==" | ||
- | nxt.ShowDevices(); | ||
- | |||
- | else if( name==" | ||
- | { | ||
- | clr = nxt.ReadColorSensor( 3, " | ||
- | app.ShowPopup( nxt.ToColorName( clr ) ); | ||
- | } | ||
- | } | ||
- | </ |