触碰过#

初始化 touchled 类#

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

此构造函数使用一个参数:

范围

描述

port

与 TouchLED 传感器连接的有效 智能端口

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

类方法#

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()#

该方法通过以下方式调用:

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

参数

描述

颜色

有效的 colorType

亮度

设置 LED 的亮度。

**返回:**无。

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

参数

描述

色调

LED 的色调。这也可以表示为十六进制代码值。

亮度

设置 LED 的亮度。

**返回:**无。

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

参数

描述

r

表示 LED 红色值的无符号 8 位整数。

表示 LED 绿色值的无符号 8 位整数。

b

表示 LED 蓝色值的无符号 8 位整数。

亮度

设置 LED 的亮度。

**返回:**无。

off()#

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

**返回:**无。

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.

参数

描述

环境

有效的 fadeType

**返回:**无。

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.

参数

描述

价值

有效的 colorType

**返回:**无。

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.

参数

描述

价值

亮度范围为 0 - 255。

**返回:**无。

pressed()#

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

参数

描述

打回来

当按下 TouchLED 传感器时将调用的函数。

**返回:**无。

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

参数

描述

打回来

当 TouchLED 传感器被释放时将调用的函数。

**返回:**无。

// 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);
}

timestamp()#

The timestamp() method requests the timestamp of the last received status packet from the Touch LED Sensor.

**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。

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.