NxtColorSensor

Last Updated On 2021-07-16

Version 1MinSDK 7Tutorial Video

A component that provides a high-level interface to a color sensor on a LEGO MINDSTORMS NXT robot.


Properties

You can set the below properties in the UI part of the builder.

  • AboveRangeEventEnabled - it's a boolean value which is set to false by default.
  • BelowRangeEventEnabled - it's a boolean value which is set to false by default.
  • BluetoothClient - it's a BluetoothClient value which is set to blank by default.
  • BottomOfRange - it's a non negative integer value which is set to 256 by default.
  • ColorChangedEventEnabled - it's a boolean value which is set to false by default.
  • DetectColor - it's a boolean value which is set to true by default.
  • GenerateColor - it's a lego nxt generated color value which is set to &h00ffffff by default.
  • SensorPort - it's a lego nxt sensor port value which is set to 3 by default.
  • TopOfRange - it's a non negative integer value which is set to 767 by default.
  • WithinRangeEventEnabled - it's a boolean value which is set to false by default.

Block Properties

You can set the below blocks properties in the blocks section of the builder.

AboveRangeEventEnabled

Whether the AboveRange event should fire when the DetectColor property is set to False and the light level goes above the TopOfRange.


BelowRangeEventEnabled

Whether the BelowRange event should fire when the DetectColor property is set to False and the light level goes below the BottomOfRange.


BottomOfRange

The bottom of the range used for the BelowRange, WithinRange, and AboveRange events.


ColorChangedEventEnabled

Whether the ColorChanged event should fire when the DetectColor property is set to True and the detected color changes.


DetectColor

Whether the sensor should detect color or light. True indicates that the sensor should detect color; False indicates that the sensor should detect light. If the DetectColor property is set to True, the BelowRange, WithinRange, and AboveRange events will not occur and the sensor will not generate color. If the DetectColor property is set to False, the ColorChanged event will not occur.


GenerateColor

The color that should generated by the sensor. Only None, Red, Green, or Blue are valid values. The sensor will not generate color when the DetectColor property is set to True.


TopOfRange

The top of the range used for the BelowRange, WithinRange, and AboveRange events.


WithinRangeEventEnabled

Whether the WithinRange event should fire when the DetectColor property is set to False and the light level goes between the BottomOfRange and the TopOfRange.



Methods

You can set the below method blocks in the blocks section of the builder.

GetColor

Returns the current detected color, or the color None if the color can not be read or if the DetectColor property is set to False.

GetLightLevel

Returns the current light level as a value between 0 and 1023, or -1 if the light level can not be read or if the DetectColor property is set to True.


Events

You can set the below event blocks in the blocks section of the builder.

AboveRange

Light level has gone above the range. The AboveRange event will not occur if the DetectColor property is set to True or if the AboveRangeEventEnabled property is set to False.

BelowRange

Light level has gone below the range. The BelowRange event will not occur if the DetectColor property is set to True or if the BelowRangeEventEnabled property is set to False.

ColorChanged

Detected color has changed. The ColorChanged event will not occur if the DetectColor property is set to False or if the ColorChangedEventEnabled property is set to False.

WithinRange

Light level has gone within the range. The WithinRange event will not occur if the DetectColor property is set to True or if the WithinRangeEventEnabled property is set to False.