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.

readLightIntensity

Read intensity of light that reaches color sensor

Syntax

intensity = readLightIntensity(mycolorsensor,mode)

Description

example

intensity = readLightIntensity(mycolorsensor,mode) measures the intensity of the light that reaches the color sensor, and returns it as value from 0 to 100 (dark to light). The default mode of this function measures ambient light from the environment. When you set the mode to measure reflected light, the sensor emits light from a red LED and measures the amount of light reflected by nearby objects.

Examples

collapse all

Measure ambient and reflected light using 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 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

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

Read ambient or reflected light, specified as a string.

Example: 'reflected'

Data Types: char

Output Arguments

collapse all

Relative light intensity, returned as an int32 value, from 0 to 100 (dark to light).