óptico#

Inicializando la clase óptica#

Un sensor óptico se crea utilizando el siguiente constructor:

The optical constructor creates an optical object.

Parámetro

Descripción

port

Un Puerto inteligente válido al que está conectado el sensor óptico.

// Construct an Optical Sensor "Optical" with the
// optical class.
optical Optical = optical(PORT1);

This Optical object will be used in all subsequent examples throughout this API documentation when referring to optical class methods.

Métodos de clase#

hue()#

The hue() method returns the value of the hue detected by the Optical Sensor.

Devuelve: Un doble que representa el valor del tono detectado por el sensor óptico como un flotante en el rango 0 - 359,99.

// Set a variable, hue, to the value of the hue detected
// by the Optical Sensor.
double hue = Optical.hue();

brightness()#

The brightness(bRaw) method returns the brightness detected by the Optical Sensor.

Parámetros

Descripción

Brazo

A boolean value to read raw brightness data instead of percentage. The default is false.

Devuelve: Un doble que representa el brillo detectado por el sensor óptico como un flotante en el rango 0 - 100%.

// Set a variable, brightness, to the value of the brightness
// detected by the Optical Sensor.    
double brightness = Optical.brightness();

// Print the brightness detected by the Optical Sensor to the
// Brain's screen.
brain.screen.print(brightness);

color()#

The color() method returns the color detected by the Optical Sensor.

Devuelve: El color detectado por el sensor óptico como una instancia de la clase color.

// Set a variable, detectColor, to the color detected by the
// Optical Sensor.
color detectColor = Optical.color();

// Print the color detected by the Optical Sensor
// to the Brain's screen.
brain.screen.print(detectColor);

isNearObject()#

The isNearObject() method returns if the Optical Sensor detects a nearby object.

Returns: true if a nearby object is detected. false if one is not.

// If an object is detected yb the Optical Sensor, print
// "near object".
if (Optical.isNearObject()){
  Brain.Screen.print("near object");
}

setLight()#

The setLight(value) method sets Optical Sensor’s LED to on or off.

Parámetros

Descripción

valor

Un ledStateType válido.

Devoluciones: Ninguna.

// Turn on LED with previous intensity.
Optical.setLight(ledState::on);

setLightPower()#

The setLightPower(value) method sets the light power of the Optical Sensor’s LED.

Parámetros

Descripción

valor

El nivel de potencia para configurar la luz de 0 a 100.

unidades

The only valid unit for reflectivity is percent.

Devoluciones: Ninguna.

// Set the light power to 50 percent.
Optical.setLightPower(50, percent);

integrationTime()#

Este método se llama de las siguientes maneras:

The integrationTime(value) method sets the Optical Sensor’s integration time.

Parámetros

Descripción

valor

El tiempo de integración en milisegundos de 5 a 700.

Devoluciones: Ninguna.

// Set the integration time to 50 milliseconds.
Optical.integrationTime(50);

The integrationTime() method gets the Optical Sensor’s integration time.

Devuelve: Un doble que representa el tiempo de integración del sensor óptico.

// Get the Optical Sensor's integration time.
double intTime = Optical.integrationTime();

objectDetectThreshold()#

The objectDetectThreshold(value) method sets the object detection threshold.

Parámetros

Descripción

valor

Un número en el rango 0 - 255. Un valor de 0 solo devolverá el valor actual.

Devuelve: El valor actual del umbral de detección de objetos.

// Set the object detection threshold to 100.
int value = Optical.objectDetectThreshold(100);

gestureEnable()#

The gestureEnable() method enables gesture mode.

Un gesto es el movimiento de un objeto detectado por el sensor óptico. Por lo tanto, si un objeto se mueve hacia arriba en el campo de visión del sensor óptico, se trata de un gesto hacia arriba. Por otro lado, si un objeto se mueve hacia abajo, se trata de un gesto hacia abajo. Lo mismo ocurre con los gestos izquierda y derecha.

Devoluciones: Ninguna.

gestureDisable()#

The gestureDisable() method disables gesture mode.

Un gesto es el movimiento de un objeto detectado por el sensor óptico. Por lo tanto, si un objeto se mueve hacia arriba en el campo de visión del sensor óptico, se trata de un gesto hacia arriba. Por otro lado, si un objeto se mueve hacia abajo, se trata de un gesto hacia abajo. Lo mismo ocurre con los gestos izquierda y derecha.

Devoluciones: Ninguna.

getGesture()#

The getGesture() method returns the gesture detected by the Optical Sensor.

Un gesto es el movimiento de un objeto detectado por el sensor óptico. Por lo tanto, si un objeto se mueve hacia arriba en el campo de visión del sensor óptico, se trata de un gesto hacia arriba. Por otro lado, si un objeto se mueve hacia abajo, se trata de un gesto hacia abajo. Lo mismo ocurre con los gestos izquierda y derecha.

Devuelve: Un objeto óptico::gesto con los últimos datos de detección de gestos.

objectDetected()#

The objectDetected(callback) method registers a callback function for when an object is detected.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se detecte un objeto.

Devoluciones: Ninguna.

// Define the detected function with a void return type,
// showing it doesn't return a value.
void detected() {
  // The Brain will print that the Optical Sensor detected
  // an object to the Brain's screen.
  Brain.Screen.print("object detected");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run detected when the Optical Sensor detects an object.
  Optical.objectDetected(detected);
}

objectLost()#

The objectLost(callback) method registers a callback function for when an object is lost.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se pierda un objeto.

Devoluciones: Ninguna.

// Define the lost function with a void return type,
// showing it doesn't return a value.
void lost() {
  // The Brain will print that the Optical Sensor lost an
  // object to the Brain's screen.
  Brain.Screen.print("object lost");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run lost when the Optical Sensor loses an object.
  Optical.objectLost(lost);
}

gestureUp()#

The gestureUp(callback) method registers a callback function for when an upward gesture is detected.

Un gesto es el movimiento de un objeto detectado por el sensor óptico. Por lo tanto, si un objeto se mueve hacia arriba en el campo de visión del sensor óptico, se trata de un gesto hacia arriba. Por otro lado, si un objeto se mueve hacia abajo, se trata de un gesto hacia abajo. Lo mismo ocurre con los gestos izquierda y derecha.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se detecte un gesto hacia arriba.

Devoluciones: Ninguna.

gestureDown()#

The gestureDown(callback) method registers a callback function for when an downward gesture is detected.

Un gesto es el movimiento de un objeto detectado por el sensor óptico. Por lo tanto, si un objeto se mueve hacia arriba en el campo de visión del sensor óptico, se trata de un gesto hacia arriba. Por otro lado, si un objeto se mueve hacia abajo, se trata de un gesto hacia abajo. Lo mismo ocurre con los gestos izquierda y derecha.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se detecte un gesto hacia abajo.

Devoluciones: Ninguna.

gestureLeft()#

The gestureLeft(callback) method registers a callback function for when an leftward gesture is detected.

Un gesto es el movimiento de un objeto detectado por el sensor óptico. Por lo tanto, si un objeto se mueve hacia arriba en el campo de visión del sensor óptico, se trata de un gesto hacia arriba. Por otro lado, si un objeto se mueve hacia abajo, se trata de un gesto hacia abajo. Lo mismo ocurre con los gestos izquierda y derecha.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se detecte un gesto hacia la izquierda.

Devoluciones: Ninguna.

gestureRight()#

The gestureRight(callback) method registers a callback function for when an rightward gesture is detected.

Un gesto es el movimiento de un objeto detectado por el sensor óptico. Por lo tanto, si un objeto se mueve hacia arriba en el campo de visión del sensor óptico, se trata de un gesto hacia arriba. Por otro lado, si un objeto se mueve hacia abajo, se trata de un gesto hacia abajo. Lo mismo ocurre con los gestos izquierda y derecha.

Parámetros

Descripción

llamar de vuelta

La función de devolución de llamada que se llamará cuando se detecte un gesto hacia la derecha.

Devoluciones: Ninguna.

timestamp()#

The timestamp() method requests the timestamp of the last received status packet from the Optical Sensor.

Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.

installed()#

The installed() method checks if the Optical Sensor is connected.

Returns: true if the Optical Sensor is connected. false if it is not.