sensor de color#
Inicializando la clase sensor de color#
The colorsensor constructor creates a colorsensor object in the specified Smart Port:
Parámetro |
Descripción |
|---|---|
|
Un Puerto inteligente válido al que está conectado el sensor de color. |
// Construct a Color Sensor "ColorSensor" with the
// colorsensor class.
colorsensor ColorSensor = colorsensor(PORT1)
This ColorSensor object will be used in all subsequent examples throughout this API documentation when referring to colorsensor class methods.
Métodos de clase#
colorname3()#
The colorname3() command returns the closest color detected to red, green, or blue.
Returns: A colorType that represents the name of the closest color detected to red, green, or blue.
// Get the name of the detected color.
colorType c = ColorSensor.colorname3();
colorname()#
The colorname() command returns the name of the closest color detected to the preset colorType values.
Returns: A colorType that represents the name of the closest color detected to twelve possible values.
// Get the name of the detected color.
colorType c = ColorSensor.colorname();
hue()#
The hue() method returns the hue value detected by the Color Sensor.
Devuelve: Un número entero que representa el tono.
brightness()#
The brightness(bRaw) method reads the brightness value from the Color Sensor.
Parámetros |
Descripción |
|---|---|
|
Whether to return the raw value detected by the Color Sensor. The default is |
Devuelve: Un número entero que representa el brillo.
isNearObject()#
The isNearObject() method returns if the proximity sensor detects an object.
Returns: true if near an object. false if it is not.
// Check if the Color Sensor is near an object.
if ColorSensor.isNearObject(){
print("near object");
}
setLight()#
Este método se llama de las siguientes maneras:
The setLight(value) method sets the Color Sensor LED on or off.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
The setLight(intensity, units) method sets the Color Sensor LED on or off.
Parámetros |
Descripción |
|---|---|
|
El valor de la intensidad a la que se fija la luz. |
|
The only valid unit for intensity is |
Devoluciones: Ninguna.
detects()#
The detects(color) command checks if the color sensor is detecting a colorType color.
Parámetros |
Descripción |
|---|---|
|
A |
Devuelve: Un valor booleano que indica si se ha detectado el color.
objectDetected()#
The objectDetected(callback) method registers a function to be called when an object detected event occurs.
Parámetros |
Descripción |
|---|---|
|
Una función que se llamará cuando ocurra un evento de detección de 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 Color 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 Color Sensor detects an object.
ColorSensor.objectDetected(detected);
}
timestamp()#
The timestamp() method requests the timestamp of the last received status packet from the Color Sensor.
Devuelve: Marca de tiempo del último paquete de estado como un entero de 32 bits sin signo en milisegundos.
installed()#
The installed() command returns if the color sensor is installed.
Devuelve: Un valor booleano que indica si el sensor de color está instalado.