Sensor óptico#
Introducción#
El sensor óptico detecta el color, el brillo y la presencia de objetos cercanos mediante una combinación de un sensor de color RGB y un sensor de proximidad. También puede usar su LED integrado para iluminar los objetos y lograr una detección más precisa.

A continuación se muestra una lista de los bloques disponibles:
configurar luz óptica – Enciende o apaga el LED del sensor óptico.
set Optical light power – Sets the power level of the Optical Sensor’s LED.
Optical found an object – Reports whether the sensor is detecting an object within range.
Optical detects color – Reports whether the Optical Sensor detects a specified color.
Optical brightness – Reports the brightness detected by the Optical Sensor.
Optical hue – Reports the hue detected by the Optical Sensor.
when Optical – Runs the attached stack of blocks when the Optical Sensor detects or loses an object.
set Optical light#
The set Optical light stack block turns the Optical Sensor’s LED on or off. This can help increase the sensor’s accuracy when detecting colors.
conjunto [Optical 1 v] luz [encendido v]
Parámetros |
Descripción |
|---|---|
dispositivo |
Which Optical Sensor to use, configured in the Devices window. |
estado |
The state of the Optical Sensor’s light: on or off. |
cuando empezó
[Turn on the sensor's LED.]
conjunto [Optical 1 v] luz [encendido v]
ajuste de potencia de luz óptica#
The set Optical light power stack block sets the brightness of the Optical Sensor’s LED. The light can help the Optical Sensor detect objects and colors more clearly.
A higher percentage makes the light brighter. A lower percentage makes the light dimmer.
If the Optical Sensor’s light is off, setting the light power above 0% will turn the light on.
If the Optical Sensor’s light is on, setting the light power at 0% will turn the light off.
Establezca la potencia de luz [Optical 1 v] al [50]%
Parámetros |
Descripción |
|---|---|
dispositivo |
Which Optical Sensor to use, configured in the Devices window. |
brillo |
The brightness to set the Optical Sensor’s light to, from 0% to 100%. Use whole numbers. |
cuando empezó
[Turn on the sensor's LED at half brightness.]
Establezca la potencia de luz [Optical 1 v] al [50]%
Optical found an object#
The Optical found an object Boolean block reports whether or not the Optical Sensor detects an object within range.
True — The Optical Sensor detects an object.
False — The Optical Sensor does not detect an object.
<[Optical 1 v] Encontraste un objeto?>
Parámetros |
Descripción |
|---|---|
dispositivo |
Which Optical Sensor to use, configured in the Devices window. |
Ejemplo
cuando empezó
[Drive forward until an object is found.]
unidad [adelante v]
esperar hasta <[Optical 1 v] Encontraste un objeto?>
deja de conducir
Optical detects color#
The Optical detects color Boolean block reports whether the Optical Sensor detects a specified color, based on the detected hue value.
True – The sensor detects the specified color.
False – The sensor does not detect the specified color.
Note: The Optical Sensor is looking for hue ranges that match the specified color. For detecting specific hue ranges, see the Optical hue reporter block.
<[Optical 1 v] detecta [rojo v]?>
Parámetros |
Descripción |
|---|---|
dispositivo |
Which Optical Sensor to use, configured in the Devices window. |
color |
Which color to look for:
|
Ejemplo
cuando empezó
[Drive forward until red is found.]
unidad [adelante v]
esperar hasta <[Optical 1 v] detecta [rojo v]?>
deja de conducir
Brillo óptico#
The Optical brightness reporter block reports how much light is reflected back to the Optical Sensor, as a percentage from 0% to 100%.
A higher percentage means more light is reflected back to the Optical Sensor. A lower percentage means less light is reflected back.
([Optical 1 v] brillo en %)
Parámetros |
Descripción |
|---|---|
dispositivo |
Which Optical Sensor to use, configured in the Devices window. |
Tonalidad óptica#
The Optical hue reporter block reports the hue detected by the Optical Sensor as a number from 0 to 359 degrees.
Hue is a way to describe color using numbers around a color wheel.

([Optical 1 v] tono en grados)
Parámetros |
Descripción |
|---|---|
dispositivo |
Which Optical Sensor to use, configured in the Devices window. |
Ejemplo
cuando empezó
[Look for the color pink using hue.]
para siempre
pantalla clara
Coloque el cursor en la fila [1] columna [1] en la pantalla
si <[300] [math_less_than v] ([Optical 1 v] tono en grados) [math_less_than v] [359]> entonces
imprimir [This is pink!] en la pantalla ▶
demás
imprimir [No pink detected!] en la pantalla ▶
cuando óptico#
The when Optical hat block runs the attached stack of blocks whenever the Optical Sensor detects or loses an object.
cuando [Optical 1 v] [detects v] un objeto :: hat events
Parámetros |
Descripción |
|---|---|
dispositivo |
Which Optical Sensor to use, configured in the Devices window. |
estado |
When the attached stack of blocks will run: detects runs when an undetected object is detected, while loses runs when a detected object is now no longer detected. |