触碰过#

初始化 touchled 类#

touchled 构造函数在指定的智能端口中创建一个 touchled 对象。

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

范围

描述

端口

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

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

当引用 touchled 类方法时,此“touch”对象将在整个 API 文档的所有后续示例中使用。

类方法#

紧迫()#

pressing() 方法返回 TouchLED 传感器当前是否被按下。

返回: 如果 TouchLED 传感器当前被按下,则返回 true。如果不是,则返回 false

在()#

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

on(color, brightenness) 方法使用预定义的颜色打开 TouchLED 传感器的 LED。

参数

描述

颜色

有效的 colorType

亮度

设置 LED 的亮度。

**返回:**无。

on(hue, brightenhance) 方法使用色调值打开 TouchLED 传感器的 LED。

参数

描述

色调

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

亮度

设置 LED 的亮度。

**返回:**无。

on(r, g, b, brightenness) 方法使用 RGB 值打开 TouchLED 传感器的 LED。

参数

描述

r

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

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

b

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

亮度

设置 LED 的亮度。

**返回:**无。

离开()#

off() 方法关闭 TouchLED 传感器的 LED。

**返回:**无。

设置淡入淡出()#

setFade(setting) 方法可更改 TouchLED 传感器的淡入淡出设置。TouchLED 传感器将使用淡入淡出类型更改为新的颜色。

参数

描述

环境

有效的 fadeType

**返回:**无。

设置颜色()#

setColor(value) 方法用于点亮 TouchLED 传感器的 LED。此方法的功能与 on() 方法类似,但该方法会使用之前的亮度级别,而不是指定的值。

参数

描述

价值

有效的 colorType

**返回:**无。

设置亮度()#

setBrightness(value) 方法可更改 TouchLED 传感器的亮度。TouchLED 传感器将使用之前使用的颜色,但亮度会有所不同。

参数

描述

价值

亮度范围为 0 - 255。

**返回:**无。

按下()#

pressed(callback) 方法注册一个在按下 TouchLED 传感器时要调用的函数。

参数

描述

打回来

当按下 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(callback) 方法注册一个在 TouchLED 传感器释放时调用的函数。

参数

描述

打回来

当 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() 方法请求触摸 LED 传感器最后接收到的状态包的时间戳。

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

安装()#

如果 TouchLED 传感器已连接到 Brain,则 installed() 方法返回。

返回: 如果 TouchLED 传感器连接到大脑,则返回 true。如果没有,则返回 false