Main Content

readColor

Read color of object in front of color sensor

Add-On Required: This feature requires the MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware add-on.

Description

color = readColor(mycolorsensor) reads the color of an object in front of the color sensor, and returns it as a string, such as red, green, or blue.

example

Examples

collapse all

Read the color of an object in front of a color sensor.

Create a connection to the EV3 brick called myev3.

myev3 = legoev3
myev3 = 

  legoev3 with properties:

      FirmwareVersion: 'V1.03E'
           HardwareID: []
            IPAddress: []
    CommunicationType: 'USB'
         BatteryLevel: 100
     ConnectedSensors: {'touch'  'gyro'  'color'  'sonic'}

The sensor appears in the list of connected sensors.

Create a connection to the color sensor.

mycolorsensor = colorSensor(myev3)
mycolorsensor = 

  colorSensor with properties:

    InputPort: 3

Read the color in front of the color sensor.

color = readColor(mycolorsensor)
color =

white

Input Arguments

collapse all

Connection to a color sensor, specified as a string that represents the object created using colorSensor.

Example: mycolorsensor

Data Types: char

Output Arguments

collapse all

The name of the color read by the color sensor, returned as a string.

Version History

Introduced in R2015a