Optical Sensor#

Introduction#

The Optical Sensing category includes blocks that control and retrieve data from the VEX IQ Optical Sensor. This sensor can detect objects, identify colors, and measure brightness and hue.

Below is a list of all blocks:

set Optical light#

The set Optical light block turns the light on the Optical Sensor on or off. The light lets the Optical Sensor see objects better if it is looking at an object in a dark area.

conjunto [Optical 1 v] luz [encendido v]

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

state

The state of the Optical Sensor’s light to set:

  • on
  • off

Example

cuando empezó
[Repeatedly flash the Optical Sensor's lights.]
para siempre
conjunto [Optical 1 v] luz [encendido v]
esperar (1) segundos
conjunto [Optical 1 v] luz [apagado v]
esperar (1) segundos

set Optical light power#

The set Optical light power block sets the brightness of the Optical Sensor’s light, helping create a more consistent and reliable light source for the sensor.

set [Optical1 v] light power to (50)%

Note: If the Optical Sensor’s light is off, this block will turn the light on.

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

brightness

The brightness of the Optical Sensor’s light from 0 to 100 as a percent.

Example

cuando empezó
[Repeatedly change the brightness of the Optical Sensor's lights.]
para siempre
set [Optical1 v] light power to (10)%
esperar (2) segundos
set [Optical1 v] light power to (50)%
esperar (2) segundos
set [Optical1 v] light power to (100)%
esperar (2) segundos

Optical found object?#

The Optical found object? block returns a Boolean indicating whether the Optical Sensor has detected an object.

  • True — The Optical Sensor has detected an object.

  • False — The Optical Sensor has not detected an object.

<[Optical 1 v] Encontraste un objeto?>

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

Example

cuando empezó
[Turn until the Optical Sensor detects an object.]
establecer la velocidad de giro a (10) [% v]
set [Optical1 v] light power to [75]%
turno [derecha v]
esperar hasta <[Optical 1 v] Encontraste un objeto?>
imprimir [Object detected] en la pantalla ◀ y coloque el cursor en la siguiente fila
deja de conducir

Optical detects color?#

The Optical detects color? block returns a Boolean indicating whether the Optical Sensor has detected a specific color.

  • True — The Optical Sensor has detected the specified color.

  • False — The Optical Sensor has not detected the specified color.

<[Optical 1 v] detecta [rojo v]?>

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

color

Which color to check for:

  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan

Example

cuando empezó
[Turn until the Optical Sensor detects a red object.]
establecer la velocidad de giro a (10) [% v]
set [Optical1 v] light power to [75]%
turno [derecha v]
esperar hasta <[Optical 1 v] detecta [rojo v]?>
imprimir [Red detected] en la pantalla ◀ y coloque el cursor en la siguiente fila
deja de conducir

Optical color name#

The Optical color name block returns the name of the color detected by the Optical Sensor.

Possible colors are:

  • red

  • green

  • blue

  • yellow

  • orange

  • purple

  • cyan

Note: This block can be inserted into the set Touch LED color block to make the Touch LED match the detected color.

([Optical 1 v] nombre de color)

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

Example

cuando empezó
[Display a message when the Optical Sensor detects red.]
esperar hasta <[Optical 1 v] detecta [rojo v]?>
imprimir ([Optical 1 v] nombre de color) en la pantalla ◀ y coloque el cursor en la siguiente fila

Optical brightness#

The Optical brightness block returns the amount of light detected by the Optical Sensor in a range from 0% to 100%.

([Optical 1 v] brillo en %)

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

Example

cuando empezó
[Display the brightness when the Optical Sensor detects red.]
esperar hasta <[Optical 1 v] detecta [rojo v]?>
imprimir ([Optical 1 v] brillo en %) en la pantalla ◀ y coloque el cursor en la siguiente fila

Optical hue#

The Optical hue block returns the hue value of the color detected by the Optical Sensor.

Hue values range from 0 to 359 degrees, corresponding to positions on the color wheel shown below.

A circular color wheel displaying a full spectrum of hues labeled with degree values around the perimeter, increasing in 30-degree increments from 0° at the top to 360°.

([Optical 1 v] tono en grados)

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

Example

cuando empezó
[Print when the Optical Sensor detects pink.]
para siempre
pantalla clara
Coloque el cursor en la fila (1) columna (1) en la pantalla
si <<([Optical 1 v] tono en grados) [math_greater_than v] [290]> y <([Optical 1 v] tono en grados) [math_less_than v] [350]>> entonces
imprimir [Pink!] en la pantalla ▶
esperar (0.1) segundos
demás
imprimir [Not pink.] en la pantalla ▶
esperar (0.1) segundos

When Optical#

The When Optical block runs the attached stack of blocks when the selected Optical Sensor detects or loses an object.

cuando [Optical 1 v] [detects v] un objeto

Parameters

Description

optical sensor

Which Optical Sensor to use, configured in the Devices window.

state

Which action to trigger the hat block:

  • detects
  • loses

Example

cuando [Optical 1 v] [detects v] un objeto
[Find an object when it is lost.]
turno [derecha v]
esperar hasta <[Optical 1 v] Encontraste un objeto?>
deja de conducir