Main Content

readLightIntensity

Read intensity of light that reaches color sensor

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

Description

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.

example

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).