LED táctil#

Introducción#

El LED táctil VEX IQ funciona como luz y botón. Puede brillar en diferentes colores para proporcionar información, como indicar que el robot está listo, mostrar el modo seleccionado o coincidir con un color detectado por otro sensor. Además, detecta cuando se toca, lo que permite iniciar o modificar el comportamiento del robot con un simple toque.

Constructor de clases#

touchled( 
  int32_t index );

Instructor de clase#

Destroys the touchled object and releases associated resources.

virtual ~touchled();

Parámetros#

Parámetro

Tipo

Descripción

index

int32_t

The Smart Port that the Touch LED is connected to, written as PORTx, where x is the port number (for example, PORT1).

Ejemplo#

// Create a touchled instance in Port 1
touchled TouchLED1 = touchled(PORT1);

Funciones de los miembros#

The touchled class includes the following member functions:

  • pressing – Returns whether the Touch LED is being pressed.

  • setColor – Sets the color of the Touch LED.

  • setFade – Sets how fast colors will fade to one another.

  • setBrightness – Sets the brightness of the Touch LED.

  • pressed – Registers a function to be called when the Touch LED is pressed.

  • released – Registers a function to be called when the Touch LED is released.

  • on – Turns the Touch LED on.

  • off – Turns the Touch LED off.

  • setBlink – Alternate the Touch LED on and off indefinitely.

  • installed – Returns whether the Touch LED is connected to the Brain.

Before calling any touchled member functions, a touchled instance must be created, as shown below:

/* This constructor is required when using VS Code.
Touch LED configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a Touch LED instance in Port 1
touchled TouchLED1 = touchled(PORT1);

pressing#

Devuelve el valor si se está pulsando el TouchLED.

Available Functions
bool pressing();

Parameters

Esta función no acepta ningún parámetro.

Return Values

Returns an bool indicating whether the Touch LED is being pressed.

  • true — The Touch LED is being pressed.
  • false — The Touch LED is not being pressed.

setColor#

Configura el LED del sensor táctil LED para que se encienda en un color específico.

Available Functions

1 Sets the Touch LED to a color using vex::color.

void setColor( 
  vex::color  color );

2 Sets LED colors using a colorType.

void setColor( 
  colorType   color );

Parameters

Parámetro

Tipo

Descripción

color

colorType

A valid color:

  • blue
  • blue_green
  • blue_violet
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
  • colorType::none
  • black
  • transparent

color

vex::color

Un color personalizado válido.

Return Values

Esta función no devuelve ningún valor.

setFade#

Configura el ajuste de desvanecimiento del sensor LED táctil. El sensor LED táctil cambiará a nuevos colores utilizando el tipo de desvanecimiento.

Available Functions
void setFade(
  fadeType  speed );

Parameters

Parámetro

Tipo

Descripción

speed

fadeType

The speed the fade will be set to:

  • fast
  • off — no fade
  • slow

Return Values

Esta función no devuelve ningún valor.

setBrightness#

Ajusta el brillo del LED táctil.

Available Functions
void setBrightness(
  uint32_t  value );

Parameters

Parámetro

Tipo

Descripción

value

uint32_t

El brillo del LED táctil se puede configurar como un porcentaje.

Return Values

Esta función no devuelve ningún valor.

pressed#

Registra una función que se llamará cuando se presione el LED táctil.

Available Functions
void pressed( void (* callback)(void) );

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(void)

Un puntero a una función que se llamará cuando se presione el LED táctil. La función no debe recibir parámetros y debe devolver void.

Return Values

Esta función no devuelve ningún valor.

Examples

Define the callback function (outside of int main())

// Display a message when LED is pressed
void LEDPressed() {
  Brain.Screen.print("LED pressed");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run LEDPressed when the value of the Touch LED is pressed.
  TouchLED1.pressed(LEDPressed);
}

released#

Registra una función que se llamará cuando se suelte el LED táctil.

Available Functions
void released( void (* callback)(void) );

Parameters

Parámetro

Tipo

Descripción

callback

void (*)(void)

Un puntero a una función que se llamará cuando se suelte el LED táctil. La función no debe recibir parámetros y debe devolver void.

Return Values

Esta función no devuelve ningún valor.

Examples

Define the callback function (outside of int main())

// Display a message when LED is released
void LEDReleased() {
  Brain.Screen.print("LED released");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run LEDReleased when the value of the Touch LED is released.
  TouchLED1.released(LEDReleased);
}

on#

Enciende el LED del sensor TouchLED utilizando colores y un brillo preestablecido.

Available Functions

1 Establece un color para el LED usando vex::color.

void on( 
  vex::color    color, 
  uint32_t      brightness = 100 );

2 Establece el color del LED usando el tono.

void on( 
  uint32_t hue, 
  uint32_t brightness = 100);

3 Establece el color del LED mediante valores RGB.

void on( 
  uint8_t   red, 
  uint8_t   green, 
  uint8_t   blue, 
  uint32_t  brightness = 100);

Parameters

Parámetro

Tipo

Descripción

color

vex::color

A valid color:

  • blue
  • blue_green
  • blue_violet
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
  • colorType::none
  • black
  • transparent

brightness

uint32_t

Opcional. El nivel de brillo al que se ajustará el LED en porcentaje; el valor predeterminado es 100.

hue

uint32_t

El tono del LED. Esto también se puede representar como un valor de código hexadecimal (0x000000).

r

uint8_t

Un número entero que representa el valor rojo del LED.

g

uint8_t

Un número entero que representa el valor verde del LED.

b

uint8_t

Un número entero que representa el valor azul del LED.

Return Values

Esta función no devuelve ningún valor.

off#

Apaga el LED táctil.

Available Functions
void off( void );

Parameters

Esta función no requiere ningún parámetro.

Return Values

Esta función no devuelve ningún valor.

installed#

Indica si el LED táctil está conectado.

Available Functions
bool installed();

Parameters

Esta función no requiere ningún parámetro.

Return Values

Devuelve un valor booleano que indica si el LED táctil está conectado:

  • true — The sensor is connected and responding.
  • false — The sensor is not connected or not detected.