Óptico#
Introducción#
El sensor óptico proporciona métodos para obtener datos de diferentes objetos. Esto permite al cerebro detectar colores, así como su tono y brillo.
For the examples below, the configured Optical Sensor will be named Optical1 and will be used in all subsequent examples throughout this API documentation when referring to optical class methods.
A continuación se muestra una lista de todos los métodos disponibles:
Acciones – Detectar objetos con el sensor óptico.
objectDetected– Registers a function to call when the Optical Sensor detects an object.objectLost– Registers a function to call when the Optical Sensor loses an object.
Mutadores: modifican las luces del sensor óptico y los rangos de detección.
setLight– Turns the Optical Sensor’s LED on or off.setLightPower– Sets the Optical Sensor’s LED to a specific brightness.objectDetectThreshold– Sets the distance an object has to be from the Optical Sensor for it to be detected.
Getters: devuelven datos de objetos con el sensor óptico.
isNearObject– Returns whether or not an object is close to the sensor.color– Return the detected color as a predefined color object.brightness– Returns the detected brightness of an object.hue– Returns the detected hue value as a float from 0 to 359.99 degrees.installed– Returns whether or not the Optical Sensor is connected to the Brain.
Constructores – Inicializan manualmente el sensor óptico.
optical– Create an Optical Sensor.
Comportamiento#
objectDetected#
objectDetected registers a function to be called when the Color Sensor detects an object.
Usage:
Optical1.objectDetected(callback);
Parámetros |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando el sensor óptico detecta un objeto. |
// Example coming soon
objectLost#
objectLost registers a function to be called when the Color Sensor loses an object.
Usage:
Optical1.objectLost(callback);
Parámetros |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando el sensor óptico pierde un objeto. |
// Example coming soon
Mutadores#
setLight#
setLight turns the Optical Sensor’s LED lights on or off.
Usage:
Optical1.setLight(state);
Parámetros |
Descripción |
|---|---|
|
The state to set the LED lights to:
|
// Example coming soon
setLightPower#
setLightPower sets the specific brightness of the Optical Sensor’s LED lights.
Usage:
Optical1.setLightPower(power, units);
Parámetros |
Descripción |
|---|---|
|
El brillo de las luces LED se establecerá entre 0 y 100. |
|
The units that represent the LED brightness:
|
// Example coming soon
objectDetectThreshold#
objectDetectThreshold sets the distance away an object must be before the Optical Sensor will detect it.
Usage:
Optical1.objectDetectThreshold(value);
Parámetros |
Descripción |
|---|---|
|
El nuevo umbral de detección como un número entero de 0 a 255. Un valor de 0 significa que no hay cambios en el umbral. |
// Example coming soon
Captadores#
isNearObject#
isNearObject returns a Boolean indicating whether or not the Optical Sensor detects a close object.
1– The Optical Sensor detects a close object.0– The Optical Sensor does not detect a close object.
Usage:
Optical1.isNearObject()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
color#
color returns the detected color from the Optical Sensor as an instance of a predefined color object, as shown below:
redgreenbluewhiteyelloworangepurplecyanred_violetvioletblue_violetblue_greenyellow_greenyellow_orangered_orangeblacktransparent
Usage:
Optical1.color()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
brightness#
brightness returns the brightness value from the Color Sensor as a double from 0 to 100.
Usage:
Optical1.brightness()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
hue#
hue returns the hue value detected by the Color Sensor as a double from 0 to 359.99.
Usage:
Optical1.hue()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
installed#
installed returns a Boolean indicating whether the Optical Sensor is currently connected to the Brain.
1– The Optical Sensor is connected to the Brain.0– The Optical Sensor is not connected to the Brain.
Usage:
Optical1.installed()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
Constructores#
optical#
optical creates an object of the optical Class in the specified port.
Usage:
optical Optical1 = optical(port);
Parámetro |
Descripción |
|---|---|
|
Which Smart Port that the Optical Sensor is connected to as |
// Example coming soon