Color#
Introducción#
El sensor de color 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 Color Sensor will be named Color1 and will be used in all subsequent examples throughout this API documentation when referring to colorsensor class methods.
A continuación se muestra una lista de todos los métodos disponibles:
Acciones: Detectar objetos con el sensor de color.
objectDetected– Calls a function when an object is detected.
Mutadores: modifican las luces del sensor de color.
setLight– Turns the Color Sensor’s LED on, off, or to a set brightness level.
Obtenedores: devuelven datos del objeto con el sensor de color.
isNearObject– Returns whether or not an object is close to the Color Sensor.detects– Returns whether or not a specified color is detected by the Color Sensor.colorname– Returns the name of the color detected by the Color Sensor.brightness– Returns the detected brightness of an object.hue– Returns the detected hue value as a float from 0 to 359.99 degrees.colorname3– Returns the closest of red, blue or green to the detected color.color– Return the detected color as a predefined color object.installed– Returns whether the Color Sensor is connected to the Brain.
Constructores: inicializan manualmente el sensor de color.
colorsensor– Create a Color Sensor.
Comportamiento#
objectDetected#
objectDetected registers a function to be called when the Color Sensor detects an object.
Usage:
Color1.objectDetected(callback);
Parámetros |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando el sensor de color detecta un objeto. |
// Example coming soon
Mutadores#
setLight#
setLight sets the state of the Color Sensor LED.
Default Usage:
Color1.setLight(value, units);
Overload Usages:
Color1.setLight(state);
Parámetros |
Descripción |
|---|---|
|
El valor de la intensidad para establecer la luz como un porcentaje de 0 a 100. |
|
The unit that represents the intensity:
|
|
A valid LED state:
|
// Example coming soon
Captadores#
isNearObject#
isNearObject returns a Boolean indicating whether or not the Color Sensor is close to an object.
1– The Color Sensor detects a close object.0– The Color Sensor does not detect a close object.
Usage:
Color1.isNearObject()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
detects#
detects returns if the Color Sensor is detecting a specified color.
1– The Color Sensor detects the color.0– The Color Sensor does not detect the color.
Usage:
Color1.detects(color)
Parámetros |
Descripción |
|---|---|
|
A valid color:
|
// Example coming soon
colorname#
colorname returns the closest matching color from a preset list shown below.
Cuando se imprime directamente, muestra el valor numérico asociado a ese color:
Color |
Valor numérico |
|---|---|
|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
Usage:
Color1.colorname()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
brightness#
brightness returns the brightness value from the Color Sensor.
Usage:
Color1.brightness(bRaw)
Parámetros |
Descripción |
|---|---|
|
Optional. A Boolean indicating whether to return the raw value detected by the Color Sensor:
|
// Example coming soon
hue#
hue returns the hue value detected by the Color Sensor as an integer.
Usage:
Color1.hue()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
colorname3#
colorname3 returns the closest color detected to red, green, or blue as an enumerated value (enum).
Color |
Valor numérico |
|---|---|
|
1 |
|
2 |
|
3 |
Usage:
Color1.colorname3()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
color#
color returns the closest predefined color object detected by the Color Sensor:
redgreenbluewhiteyelloworangepurplecyanred_violetvioletblue_violetblue_greenyellow_greenyellow_orangered_orangeblacktransparent
Usage:
Color1.color()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
installed#
installed returns a Boolean indicating whether the Color Sensor is currently connected to the Brain.
1– The Color Sensor is connected to the Brain.0– The Color Sensor is not connected to the Brain.
Usage:
Color1.installed()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
// Example coming soon
Constructores#
colorsensor#
colorsensor creates an object of the colorsensor Class in the specified port.
Usage:
colorsensor Color1 = colorsensor(port);
Parámetro |
Descripción |
|---|---|
|
Which Smart Port that the Color Sensor is connected to as |
// Example coming soon