This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

colorSensor

Connection to color sensor

Description

This object represents a connection to an EV3 Color Sensor (item number 45506). To read color and light intensity, use this object with the functions listed in Object Functions.

Creation

Syntax

mycolorsensor = colorSensor(myev3)
mycolorsensor = colorSensor(myev3,inputport)

Description

example

mycolorsensor = colorSensor(myev3) creates a connection to a color sensor. You can use this connection with the functions listed in Object Functions to read colors and measure light intensity.

If multiple color sensors are attached to the EV3 brick, this function chooses the sensor that is attached to the EV3 input port with the lowest number.

example

mycolorsensor = colorSensor(myev3,inputport) creates a connection to a color sensor that uses a specific EV3 input port defined by the InputPort property.

Input Arguments

expand all

Connection to EV3 brick, specified as a string that represents the object created using legoev3.

Example: myev3

Data Types: char

Output Arguments

expand all

Connection to color sensor, returned as an object handle.

Properties

expand all

This property is read-only.

Number of the EV3 input port that the sensor uses, returned as a double.

Example: 1

Data Types: double

Object Functions

readColorRead color of object in front of color sensor
readLightIntensityRead intensity of light that reaches color sensor

Examples

collapse all

Read the color and ambient light intensity from 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

Read the relative intensity of the ambient light that reaches the color sensor. If not specified, the default mode is 'ambient'.

intensity = readLightIntensity(mycolorsensor)
intensity =

           9

Read the relative intensity of the LED light that a nearby object reflects back to the color sensor.

intensity = readLightIntensity(mycolorsensor,'reflected')
intensity =

          53