触摸 LED#
介绍#
VEX IQ 触摸 LED 既是指示灯又是按钮。它可以发出不同颜色的光来提供反馈,例如指示机器人已准备就绪、显示所选模式或匹配其他传感器检测到的颜色,它还可以检测到触摸,让您只需轻触一下即可启动或更改机器人的行为。
类构造函数#
touchled(
int32_t index );
类析构函数#
Destroys the touchled object and releases associated resources.
virtual ~touchled();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The Smart Port that the Touch LED is connected to, written as |
例子#
// Create a touchled instance in Port 1
touchled TouchLED1 = touchled(PORT1);
成员功能#
The touchled class includes the following member functions:
pressing– Returns whether the Touch LED is being pressed.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.pressed– Registers a function to be called when the Touch LED is pressed.released– Registers a function to be called when the Touch LED is released.on– Turns the Touch LED on.off– Turns the Touch LED off.setBlink– Alternate the Touch LED on and off indefinitely.installed– Returns whether the Touch LED is connected to the Brain.
Before calling any touchled member functions, a touchled instance must be created, as shown below:
/* 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 ValuesReturns an bool indicating whether the Touch LED is being pressed.
-
true— The Touch LED is being pressed. -
false— The Touch LED is not being pressed.
setColor#
将触摸LED传感器的LED设置为特定颜色。
Available Functions1 — Sets the Touch LED to a color using
vex::color.void setColor( vex::color color );
Parameters2 — Sets LED colors using a
colorType.void setColor( colorType color );
范围 |
类型 |
描述 |
|---|---|---|
|
|
A valid color:
|
|
|
有效的自定义颜色。 |
此函数不返回值。
setFade#
设置触摸式 LED 传感器的渐变效果。触摸式 LED 传感器将根据所选渐变效果变换颜色。
Available Functionsvoid setFade(
fadeType speed );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The speed the fade will be set to:
|
此函数不返回值。
setBrightness#
设置触摸式 LED 的亮度。
Available Functionsvoid setBrightness(
uint32_t value );
范围 |
类型 |
描述 |
|---|---|---|
|
|
以百分比形式设置触摸 LED 的亮度。 |
此函数不返回值。
pressed#
注册一个在触摸 LED 被按下时要调用的函数。
Available Functionsvoid pressed( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在触摸 LED 被按下时调用。该函数不能接受任何参数,并且必须返回 void 类型。 |
此函数不返回值。
ExamplesDefine the callback function (outside of
int main())// Display a message when LED is pressed void LEDPressed() { Brain.Screen.print("LED pressed"); }Register the callback inside
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。 |
此函数不返回值。
ExamplesDefine the callback function (outside of
int main())// Display a message when LED is released void LEDReleased() { Brain.Screen.print("LED released"); }Register the callback inside
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 设置 LED 的颜色。
void on( vex::color color, double onTime = 0.25, double offTime = 0.25 );
2 — 使用色调设置 LED 颜色。
void on( uint32_t hue, double onTime = 0.25, double offTime = 0.25 );
Parameters3 — 通过 RGB 值设置 LED 颜色。
void setColor( 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.