触摸LED#

介绍#

VEX IQ(第二代)触摸 LED 类别提供了与触摸 LED 交互的方法。

For the examples below, the configured Touch LED will be named TouchLED1 and will be used in all subsequent examples throughout this API documentation when referring to touchled class methods.

以下是所有可用方法的列表:

操作——与触摸 LED 交互。

  • pressed – Calls a function when the Touch LED is pressed.

  • released – Calls a function when the Bumper Switch is released.

  • on – Turns the Touch LED on.

  • off – Turns the Touch LED off.

改变器——改变触摸 LED 的颜色、亮度和设置。

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

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

Getters – 从触摸 LED 返回数据。

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

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

构造函数 – 手动初始化触摸 LED。

行动#

pressed#

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

Usage:
TouchLED1.pressed(callback);

参数

描述

callback

先前定义的 函数 在按下触摸 LED 时执行。

// Turn the LED red
void onTouchPressed() {
  TouchLED1.setColor(red);
}

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

  // Call onTouchPressed when the Touch LED is pressed
  TouchLED1.pressed(onTouchPressed);
}

released#

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

Usage:
TouchLED1.released(callback);

参数

描述

callback

先前定义的在释放触摸 LED 时执行的功能。

// Turn the LED off
void onTouchReleased() {
  TouchLED1.off();
}

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

  TouchLED1.setColor(blue);
  // Call onTouchReleased when the Touch LED is released
  TouchLED1.released(onTouchReleased);
}

on#

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

Default Usage:
TouchLED1.on(color, brightness);

Overload Usages:
TouchLED1.on(hue, brightness);
TouchLED1.on(r, g, b, brightness);

参数

描述

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

可选。LED 亮度的百分比,默认为 100。

hue

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

r

表示 LED 红色值的整数。

g

表示 LED 绿色值的整数。

b

表示 LED 蓝色值的整数。

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

  // Turn LED on using a predefined color with 100 brightness
  TouchLED1.on(green, 100);
  wait(1, seconds);

  // Turn LED on using hexcode (FF2A00, 75 brightness)
  TouchLED1.on(0xFF2A00, 75);
  wait(1, seconds);

  // Turn LED on using RGB values (0, 30, 255, 50 brightness)
  TouchLED1.on(0, 30, 255, 50);
}

off#

off turns the Touch LED off.

Usage:
TouchLED1.off();

参数

描述

该方法没有参数。

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

  // Turn LED on, wait, then turn off
  TouchLED1.setColor(yellow);
  wait(2, seconds);
  TouchLED1.off();
}

修改器#

setColor#

setColor turns the LED of the Touch LED Sensor on to a specific color.

Usage:
TouchLED1.setColor(color);

参数

描述

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
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Alternate between colors
  while (true) {
    TouchLED1.setColor(blue_violet);
    wait(0.5, seconds);
    TouchLED1.setColor(blue_green);
    wait(0.5, seconds);
  }
}

setFade#

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

Usage:
TouchLED1.setFade(speed);

参数

描述

speed

The speed the fade will be set to:

  • fast
  • off — no fade
  • slow
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Set the fade speed to slow
  TouchLED1.setFade(slow);
}

setBrightness#

setBrightness sets the brightness of the Touch LED.

Usage:
TouchLED1.setBrightness(value);

参数

描述

value

触摸 LED 的亮度设置为百分比。

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

  // Show different brightness levels
  TouchLED1.setColor(green);
  wait(1, seconds);

  TouchLED1.setBrightness(25);
  wait(1, seconds);

  TouchLED1.setBrightness(100);
}

吸气剂#

pressing#

pressing returns a Boolean indicating whether the Touch LED Sensor is currently being pressed.

  • 1 – The Touch LED is currently bring pressed.

  • 0 – The Touch LED is not currently being pressed.

Usage:
TouchLED1.pressing()

参数

描述

该方法没有参数。

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

  // Only turn green when the Touch LED is being pressed
  while (true) {
    if (TouchLED1.pressing()) {
      TouchLED1.setColor(green);

    } else {
      TouchLED1.off();
    }
  }
}

installed#

installed returns a Boolean indicating whether the Touch LED is currently connected to the Brain.

  • 1 – The TouchLED is connected to the Brain.

  • 0 – The TouchLED is not connected to the Brain.

Usage:
TouchLED1.installed()

参数

描述

该方法没有参数。

构造函数#

touchled#

touchled creates an object of the touchled Class in the specified port.

Usage:
touchled TouchLED1 = touchled(port);

范围

描述

port

Which Smart Port that the Touch LED is connected to as PORT followed by the port number, ranging from 1 to 12.

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

  // Create a Touch LED in Port 1
  touchled myTouchLED = touchled(PORT1);
}