触摸 LED#
介绍#
VEX IQ 触摸 LED 既是指示灯又是按钮。它可以发出不同颜色的光来提供反馈,例如指示机器人已准备就绪、显示所选模式或匹配其他传感器检测到的颜色,它还可以检测到触摸,让您只需轻触一下即可启动或更改机器人的行为。
类构造函数#
touchled(
int32_t index );
类析构函数#
Destroys the touchled object and releases associated resources.
virtual ~touchled();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
触摸 LED 连接的智能端口,写成 |
例子#
// Create a touchled instance in Port 1
touchled TouchLED1 = touchled(PORT1);
成员功能#
touchled 类包含以下成员函数:
pressing– 返回触摸 LED 是否被按下。setColor– 设置触摸 LED 的颜色。setFade– 设置颜色之间淡入淡出的速度。setBrightness– 设置触摸 LED 的亮度。pressed– 注册一个在触摸 LED 被按下时要调用的函数。released– 注册一个在触摸 LED 释放时要调用的函数。on– 打开触摸 LED。off– 关闭触摸 LED。setBlink– 无限循环地交替打开和关闭触摸 LED。installed– 返回触摸 LED 是否连接到大脑。
在调用任何 touchled 函数之前,必须先创建一个 touchled ,如下所示:
/* This constructor is required when using VS Code.
Touch LED 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#
返回触摸LED当前是否被按下。
Available Functionsbool pressing();
此函数不接受任何参数。
Return Values返回 bool 布尔值,指示触摸 LED 是否被按下。
-
true— The Touch LED is being pressed. -
false— The Touch LED is not being pressed.
setColor#
将触摸LED传感器的LED设置为特定颜色。
Available Functions1 — 使用
vex::color将触摸 LED 设置为某种颜色。void setColor( vex::color color );
Parameters2 — 使用
colorType设置 LED 颜色。void setColor( colorType color );
范围 |
类型 |
描述 |
|---|---|---|
|
|
A valid color:
|
|
|
有效的自定义颜色。 |
此函数不返回值。
setFade#
设置触摸式 LED 传感器的渐变效果。触摸式 LED 传感器将根据所选渐变效果变换颜色。
Available Functionsvoid setFade(
fadeType speed );
范围 |
类型 |
描述 |
|---|---|---|
|
|
淡入淡出速度可设置为:
|
此函数不返回值。
setBrightness#
设置触摸式 LED 的亮度。
Available Functionsvoid setBrightness(
uint32_t value );
范围 |
类型 |
描述 |
|---|---|---|
|
|
以百分比形式设置触摸 LED 的亮度。 |
此函数不返回值。
pressed#
注册一个在触摸 LED 被按下时要调用的函数。
Available Functionsvoid pressed( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在触摸 LED 被按下时调用。该函数不能接受任何参数,并且必须返回 void 类型。 |
此函数不返回值。
Examples定义回调函数(在
int main()之外)// Display a message when LED is pressed void LEDPressed() { Brain.Screen.print("LED pressed"); }在
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#
注册一个在触摸 LED 释放时要调用的函数。
Available Functionsvoid released( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在触摸 LED 释放时调用。该函数不得接受任何参数,且必须返回 void。 |
此函数不返回值。
Examples定义回调函数(在
int main()之外)// Display a message when LED is released void LEDReleased() { Brain.Screen.print("LED released"); }在
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#
使用颜色和设定的亮度打开触摸LED传感器的LED灯。
Available Functions1 — 使用 vex::color 设置 LED 的颜色。
void on( vex::color color, uint32_t brightness = 100 );
2 — 使用色调设置 LED 颜色。
void on( uint32_t hue, uint32_t brightness = 100);
Parameters3 — 通过 RGB 值设置 LED 颜色。
void on( uint8_t red, uint8_t green, uint8_t blue, uint32_t brightness = 100);
范围 |
类型 |
描述 |
|---|---|---|
|
|
A valid color:
|
|
|
可选。LED 亮度设置百分比,默认值为 100。 |
|
|
LED 的色调。这也可以用十六进制代码值 (0x000000) 表示。 |
|
|
表示 LED 红色值的整数。 |
|
|
表示 LED 绿色值的整数。 |
|
|
表示 LED 蓝色值的整数。 |
此函数不返回值。
off#
关闭触摸指示灯。
Available Functionsvoid off( void );
此函数不接受任何参数。
Return Values此函数不返回值。
setBlink#
触摸指示灯反复闪烁,呈开和关交替模式。
Available Functions1 — 使用
vex::color设置闪烁颜色。void setBlink( vex::color color, double onTime = 0.25, double offTime = 0.25 );
2 — 使用十六进制颜色值设置闪烁颜色。
void setBlink( uint32_t hue, double onTime = 0.25, double offTime = 0.25 );
Parameters3 — 使用
colorType设置闪烁颜色。void setBlink( colorType color, double onTime = 0.25, double offTime = 0.25 );
范围 |
类型 |
描述 |
|---|---|---|
|
|
A valid color:
|
|
|
可选。LED 每次闪烁周期持续亮起的秒数,默认值为 0.25 秒。 |
|
|
可选。LED 每次闪烁周期关闭的持续时间(以秒为单位),默认值为 0.25 秒。 |
|
|
LED灯的色调。这也可以用十六进制代码值表示。 |
|
|
有效的自定义颜色。 |
此函数不返回值。
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#
返回触摸LED是否已连接。
Available Functionsbool installed();
此函数不接受任何参数。
Return Values返回一个布尔值,指示触摸 LED 是否已连接:
-
true— The sensor is connected and responding. -
false— The sensor is not connected or not detected.