Touch LED#

Introduction#

The touchled class is used to detect when the Touch LED is pressed and released and set colors.

Class Constructor#

touchled( 
  int32_t index );

Class Destructor#

Destroys the touchled object and releases associated resources.

virtual ~touchled();

Parameters#

Parameter

Type

Description

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).

Example#

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

Member Functions#

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.
Distance Sensor 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#

Returns if the TouchLED is currently being pressed.

Available Functions
bool pressing();

Parameters

This function does not accept any parameters.

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#

Sets the LED of the Touch LED Sensor on to a specific color.

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

Parameter

Type

Description

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

A valid custom color.

Return Values

This function does not return a value.

setFade#

Sets the fade setting of the Touch LED Sensor. The Touch LED Sensor will change to new colors using the fade type.

Available Functions
void setFade(
  fadeType  speed );

Parameters

Parameter

Type

Description

speed

fadeType

The speed the fade will be set to:

  • fast
  • off — no fade
  • slow
Return Values

This function does not return a value.

setBrightness#

Sets the brightness of the Touch LED.

Available Functions
void setBrightness(
  uint32_t  value );

Parameters

Parameter

Type

Description

value

uint32_t

The brightness of the Touch LED to set as a percent.

Return Values

This function does not return a value.

pressed#

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

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

Parameters

Parameter

Type

Description

callback

void (*)(void)

A pointer to a function that will be called when the Touch LED is pressed. The function must take no parameters and return void.

Return Values

This function does not return a value.

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#

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

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

Parameters

Parameter

Type

Description

callback

void (*)(void)

A pointer to a function that will be called when the Touch LED is released. The function must take no parameters and return void.

Return Values

This function does not return a value.

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#

Turns the LED of the TouchLED Sensor on using predefined colors and a set brightness.

Available Functions

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

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

2 Sets LED color using hue.

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

3 Sets LED color by rgb values.

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

Parameters

Parameter

Type

Description

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

Optional. The brightness at which to set the LED in percent, defaulting to 100.

hue

uint32_t

The hue of the LED. This can also be represented as a Hexcode value (0x000000).

r

uint8_t

An integer representing the red value of the LED.

g

uint8_t

An integer representing the green value of the LED.

b

uint8_t

An integer representing the blue value of the LED.

Return Values

This function does not return a value.

off#

Turns the Touch LED off.

Available Functions
void off( void );

Parameters

Parameters

Type

Description

This method has no parameters.

Return Values

This function does not return a value.

installed#

Returns whether the Touch LED is connected.

Available Functions
bool installed();

Parameters

This function does not take any parameters.

Return Values

Returns a Boolean indicating whether the Touch LED is connected:

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