觸摸 LED#

介紹#

VEX IQ 觸摸 LED 既是指示燈又是按鈕。它可以發出不同顏色的光來提供反饋,例如指示機器人已準備就緒、顯示所選模式或匹配其他感測器檢測到的顏色,它還可以檢測到觸摸,讓您只需輕觸一下即可啟動或更改機器人的行為。

類別建構函數#

touchled( 
  int32_t index );

類別析構函數#

Destroys the touchled object and releases associated resources.

virtual ~touchled();

參數#

範圍

類型

描述

index

int32_t

觸摸 LED 連接的智慧型端口,寫成 PORTx,其中 x 是端口號(例如, PORT1)。

例子#

// 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 Functions
bool pressing();

Parameters

此函數不接受任何參數。

Return Values

返回 bool 布林值,指示觸摸 LED 是否被按下。

  • true — The Touch LED is being pressed.
  • false — The Touch LED is not being pressed.

setColor#

將觸摸LED感測器的LED設定為特定顏色。

Available Functions

1 — 使用 vex::color將觸控 LED 設定為某種顏色。

void setColor( 
  vex::color  color );

2 — 使用 colorType設定 LED 顏色。

void setColor( 
  colorType   color );

Parameters

範圍

類型

描述

color

colorType

A valid color:

  • blue
  • blue_green
  • blue_violet
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
  • colorType::none
  • black
  • transparent

color

vex::color

有效的自訂顏色。

Return Values

此函數不傳回值。

setFade#

設定觸控式 LED 感應器的漸層效果。觸控式 LED 感應器將根據所選漸層效果變換顏色。

Available Functions
void setFade(
  fadeType  speed );

Parameters

範圍

類型

描述

speed

fadeType

淡入淡出速度可設定為:

  • fast
  • off — 無淡入淡出
  • slow

Return Values

此函數不傳回值。

setBrightness#

設定觸控式 LED 的亮度。

Available Functions
void setBrightness(
  uint32_t  value );

Parameters

範圍

類型

描述

value

uint32_t

以百分比形式設定觸控 LED 的亮度。

Return Values

此函數不傳回值。

pressed#

註冊一個在觸摸 LED 被按下時要呼叫的函數。

Available Functions
void pressed( void (* callback)(void) );

Parameters

範圍

類型

描述

callback

void (*)(void)

指向一個函數的指針,該函數將在觸摸 LED 被按下時調用。此函數不能接受任何參數,且必須傳回 void 類型。

Return Values

此函數不傳回值。

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 Functions
void released( void (* callback)(void) );

Parameters

範圍

類型

描述

callback

void (*)(void)

指向一個函數的指針,該函數將在觸摸 LED 釋放時調用。函數不得接受任何參數,且必須傳回 void。

Return Values

此函數不傳回值。

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 Functions

1 — 使用 vex::color 設定 LED 的顏色。

void on( 
  vex::color    color, 
  uint32_t      brightness = 100 );

2 — 使用色調設定 LED 顏色。

void on( 
  uint32_t hue, 
  uint32_t brightness = 100);

3 — 透過 RGB 值設定 LED 顏色。

void on( 
  uint8_t   red, 
  uint8_t   green, 
  uint8_t   blue, 
  uint32_t  brightness = 100);

Parameters

範圍

類型

描述

color

vex::color

A valid color:

  • blue
  • blue_green
  • blue_violet
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
  • colorType::none
  • black
  • transparent

brightness

uint32_t

可選。 LED 亮度設定百分比,預設值為 100。

hue

uint32_t

LED 的色調。這也可以用十六進位代碼值 (0x000000) 表示。

red

uint8_t

表示 LED 紅色值的整數。

green

uint8_t

表示 LED 綠色值的整數。

blue

uint8_t

表示 LED 藍色值的整數。

Return Values

此函數不傳回值。

off#

關閉觸摸指示燈。

Available Functions
void off( void );

Parameters

此函數不接受任何參數。

Return Values

此函數不傳回值。

installed#

返回觸控LED是否已連線。

Available Functions
bool installed();

Parameters

此函數不接受任何參數。

Return Values

傳回布林值,指示觸控 LED 是否已連接:

  • true — The sensor is connected and responding.
  • false — The sensor is not connected or not detected.