touchled#

Initializing the touchled Class#

The touchled constructor creates a touchled object in the specified Smart Port.

This constructor use one parameter:

Parameter

Description

port

A valid Smart Port that the TouchLED Sensor is connected to.

// Construct the Brain.
brain Brain;
// Construct a TouchLED Sensor "touch" with the
// TouchLED class.
touchled touch = touchled(PORT1);

This touch object will be used in all subsequent examples throughout this API documentation when referring to touchled class methods.

Class Methods#

pressing()#

The pressing() method returns whether the TouchLED Sensor is currently being pressed.

Returns: true if the TouchLED Sensor is currently being pressed. false if it is not.

on()#

This method is called in the following ways:

The on(color, brightness) method turns the LED of the TouchLED Sensor on using predefined colors.

Parameters

Description

color

A valid ColorType.

brightness

The brightness at which to set the LED.

Returns: None.

The on(hue, brightness) method turns the LED of the TouchLED Sensor on using hue values.

Parameters

Description

hue

The hue of the LED. This can also be represented as a Hexcode value.

brightness

The brightness at which to set the LED.

Returns: None.

The on(r, g, b, brightness) method turns the LED of the TouchLED Sensor on using RGB values.

Parameters

Description

r

An unsigned 8 bit integer representing the Red value of the LED.

g

An unsigned 8 bit integer representing the Green value of the LED.

b

An unsigned 8 bit integer representing the Blue value of the LED.

brightness

The brightness at which to set the LED.

Returns: None.

off()#

The off() method turns the LED of the TouchLED Sensor off.

Returns: None.

setFade()#

The setFade(setting) method changes the fade setting of the TouchLED Sensor . The TouchLED Sensor will change to new colors using the fade type.

Parameters

Description

setting

A valid FadeType.

Returns: None.

setColor()#

The setColor(value) method turns the LED of the TouchLED Sensor on. This method has similar functionality to the on() method but this method will use the previous brightness level instead of a specified value.

Parameters

Description

value

A valid ColorType.

Returns: None.

setBrightness()#

The setBrightness(value) method changes the brightness of the TouchLED Sensor. The TouchLED Sensor will be turned on using the previously used color but with a different brightness.

Parameters

Description

value

Brightness in the range of 0 - 255.

Returns: None.

pressed()#

The pressed(callback) method registers a function to be called when the TouchLED Sensor is pressed.

Parameters

Description

callback

A function that will be called when the TouchLED Sensor is pressed.

Returns: None.

// Define the touchLEDPressed function with a void return type,
// showing it doesn't return a value.
void touchLEDPressed() {
  // The Brain will print that the TouchLED Sensor was pressed on the
  // Brain's screen.
  Brain.Screen.print("TouchLED Sensor pressed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run touchLEDPressed when the value of the TouchLED Sensor
  // is pressed.
  touch.pressed(touchLEDPressed);
}

released()#

The released(callback) method registers a function to be called when the TouchLED Sensor is released.

Parameters

Description

callback

A function that will be called when the TouchLED Sensor is released.

Returns: None.

// Define the touchLEDReleased function with a void return type,
// showing it doesn't return a value.
void touchLEDReleased() {
  // The Brain will print that the TouchLED Sesor was released 
  // on the Brain's screen.
  Brain.Screen.print("TouchLED Sensor released");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run touchLEDReleased when the value of the TouchLED Sensor 
  // is released.
  touch.released(touchLEDReleased);
}

installed()#

The installed() method returns if the TouchLED Sensor is connected to the Brain.

Returns: true if the TouchLED Sensor is connected to the Brain. false if it is not.