Ev3ColorSensor
Last Updated On 2021-07-16
Version 2MinSDK 7Tutorial Video
A component that provides a high-level interface to a color sensor on a LEGO MINDSTORMS EV3 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 30 by default.
- ColorChangedEventEnabled - it's a boolean value which is set to false by default.
- Mode - it's a lego ev3 color sensor mode value which is set to reflected by default.
- SensorPort - it's a lego ev3 sensor port value which is set to 1 by default.
- TopOfRange - it's a non negative integer value which is set to 60 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 light level goes above the TopOfRange.
BelowRangeEventEnabled
Whether the BelowRange event should fire when the light level goes below the BottomOfRange.
BluetoothClient
The BluetoothClient component that should be used for communication.
BottomOfRange
The bottom of the range used for the BelowRange, WithinRange, and AboveRange events.
ColorChangedEventEnabled
Whether the ColorChanged event should fire when the Mode property is set to "color" and the detected color changes.
Mode
Specifies the mode of the sensor.
TopOfRange
The top of the range used for the BelowRange, WithinRange, and AboveRange events.
WithinRangeEventEnabled
Whether the WithinRange event should fire when 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.
GetColorCode
It returns the color code from 0 to 7 corresponding to no color, black, blue, green, yellow, red, white and brown.
GetColorName
Return the color name in one of "No Color", "Black", "Blue", "Green", "Yellow", "Red", "White", "Brown".
GetLightLevel
It returns the light level in percentage, or -1 when the light level cannot be read.
SetAmbientMode
Make the sensor read the light level without reflected light.
SetColorMode
Enter the color detection mode.
SetReflectedMode
Make the sensor read the light level with reflected light.
Events
You can set the below event blocks in the blocks section of the builder.
AboveRange
Light level has gone above the range.
BelowRange
Light level has gone below the range.
ColorChanged
Called when the detected color has changed. The ColorChanged event will occur if the Mode property is set to "color" and the ColorChangedEventEnabled property is set to True.
WithinRange
Light level has gone within the range.