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 |
|---|---|---|
|
|
The Smart Port that the Touch LED is connected to, written as |
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 Functionsbool pressing();
This function does not accept any parameters.
Return ValuesReturns 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 Functions1 — Sets the Touch LED to a color using
vex::color.void setColor( vex::color color );
Parameters2 — Sets LED colors using a
colorType.void setColor( colorType color );
Parameter |
Type |
Description |
|---|---|---|
|
|
A valid color:
|
|
|
A valid custom color. |
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 Functionsvoid setFade(
fadeType speed );
Parameter |
Type |
Description |
|---|---|---|
|
|
The speed the fade will be set to:
|
This function does not return a value.
setBrightness#
Sets the brightness of the Touch LED.
Available Functionsvoid setBrightness(
uint32_t value );
Parameter |
Type |
Description |
|---|---|---|
|
|
The brightness of the Touch LED to set as a percent. |
This function does not return a value.
pressed#
Registers a function to be called when the Touch LED is pressed.
Available Functionsvoid pressed( void (* callback)(void) );
Parameter |
Type |
Description |
|---|---|---|
|
|
A pointer to a function that will be called when the Touch LED is pressed. The function must take no parameters and return void. |
This function does not return a value.
ExamplesDefine 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 Functionsvoid released( void (* callback)(void) );
Parameter |
Type |
Description |
|---|---|---|
|
|
A pointer to a function that will be called when the Touch LED is released. The function must take no parameters and return void. |
This function does not return a value.
ExamplesDefine 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 Functions1 — 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);
Parameters3 — Sets LED color by rgb values.
void on( uint8_t red, uint8_t green, uint8_t blue, uint32_t brightness = 100);
Parameter |
Type |
Description |
|---|---|---|
|
|
A valid color:
|
|
|
Optional. The brightness at which to set the LED in percent, defaulting to 100. |
|
|
The hue of the LED. This can also be represented as a Hexcode value (0x000000). |
|
|
An integer representing the red value of the LED. |
|
|
An integer representing the green value of the LED. |
|
|
An integer representing the blue value of the LED. |
This function does not return a value.
off#
Turns the Touch LED off.
Available Functionsvoid off( void );
Parameters |
Type |
Description |
|---|---|---|
This method has no parameters. |
This function does not return a value.
setBlink#
Repeatedly blinks the Touch LED in an on and off pattern.
Available Functions1 — Sets the LED to a color using vex::color.
void on( vex::color color, double onTime = 0.25, double offTime = 0.25 );
2 — Sets LED color using hue.
void on( uint32_t hue, double onTime = 0.25, double offTime = 0.25 );
Parameters3 — Sets LED color by rgb values.
void setColor( colorType color, double onTime = 0.25, double offTime = 0.25 );
Parameter |
Type |
Description |
|---|---|---|
|
|
A valid color:
|
|
|
Optional. The period in seconds the LED will be on in the blinking pattern in seconds, defaulting to 0.25 seconds. |
|
|
Optional. The period in seconds the LED will be off in the blinking pattern in seconds, defaulting to 0.25 seconds. |
|
|
The hue of the LED. This can also be represented by a Hexcode value. |
|
|
A valid custom color. |
This function does not return a value.
Notes - Calling [off](#off) will not stop the blinking behavior. To stop the blinking behavior, set the LED brightness to 0 with [setBrightness](#setbrightness).
installed#
Returns whether the Touch LED is connected.
Available Functionsbool installed();
This function does not take any parameters.
Return ValuesReturns 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.