觸摸 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 秒。 |
|
|
十六進位顏色值(例如, |
|
|
有效的自訂顏色。 |
此函數不傳回值。
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.