觸摸 LED#
介紹#
VEX IQ 觸摸 LED 既是指示燈又是按鈕。它可以發出不同顏色的光來提供反饋,例如指示機器人已準備就緒、顯示所選模式或匹配其他感測器檢測到的顏色,它還可以檢測到觸摸,讓您只需輕觸一下即可啟動或更改機器人的行為。
本頁面使用 touchled_1 作為觸控 LED 的範例名稱。您可以根據需要將其替換為您自己配置的名稱。
以下是所有方法的清單:
操作-與觸控式LED互動。
pressed— 註冊一個在觸摸 LED 被按下時要呼叫的函數。released— 註冊一個在觸摸 LED 釋放時要呼叫的函數。on— 開啟觸控 LED。off— 關閉觸控 LED。toggle— 開啟或關閉觸控 LED。
自訂設定-變更觸控式 LED 的顏色、亮度和設定。
set_color— 設定觸控 LED 的顏色。set_fade— 設定顏色之間淡入淡出的速度。set_brightness— 設定觸控 LED 的亮度。set_blink— 無限循環地交替開啟和關閉觸控 LED。
獲取器 — 返回觸摸 LED 的資料。
建構函式 — 手動初始化和配置觸控 LED。
Touchled— 建立一個觸控 LED。
行動#
pressed#
pressed 註冊一個在觸摸 LED 被按下時要呼叫的函數。
Usage:
touchled_1.pressed(callback, arg)
參數 |
描述 |
|---|---|
|
一個預先定義好的函數,當觸摸 LED 被按下時執行。 |
|
# Turn blue while the Touch LED is pressed
def light_blue():
touchled_1.set_color(Color.BLUE)
touchled_1.pressed(light_blue)
released#
released 註冊一個在觸摸 LED 釋放時要呼叫的函數。
Usage:
touchled_1.released(callback, arg)
參數 |
描述 |
|---|---|
|
一個預先定義好的函數,當觸摸 LED 釋放時執行。 |
|
# Turn red when the Touch LED is released
def light_red():
touchled_1.set_color(Color.RED)
touchled_1.released(light_red)
on#
on 表示將觸控 LED 的亮度設定為 100%,從而開啟觸控 LED。
Usage:
touchled_1.on(value)
參數 |
描述 |
|---|---|
|
选修的。 设置 LED 灯颜色:
|
# Turn green when the robot is moving
touchled_1.on(Color.GREEN)
drivetrain.drive_for(FORWARD, 5)
touchled_1.off()
off#
off 將觸控 LED 的亮度設定為 0%,從而關閉觸控 LED。
Usage:
touchled_1.off()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Turn off Touch LED when movement is over
touchled_1.on(Color.GREEN)
drivetrain.drive_for(FORWARD, 5)
touchled_1.off()
toggle#
toggle 可開啟或關閉觸控 LED 燈。如果 LED 燈目前亮著, toggle 可將其亮度設定為 0%,即關閉 LED 燈。如果 LED 燈已關閉, toggle 可將其亮度設定為 100%,即開啟 LED 燈。
Usage:
touchled_1.toggle()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Turn the Touch LED off and on
touchled_1.set_color(Color.RED)
while True:
touchled_1.toggle()
wait(0.5,SECONDS)
突變體#
set_color#
set_color 設定觸控 LED 的顏色。如果使用此方法時觸控 LED 尚未點亮,則會將亮度設為 100% 以開啟觸控 LED。
Usage:
touchled_1.set_color(color)
參數 |
描述 |
|---|---|
|
Optional. Sets the LED’s color to:
set_color will turn the Touch LED on with the previously set color.You can also specify a custom color. |
# Change colors between blue and green
while True:
touchled_1.set_color(Color.BLUE)
wait(0.5, SECONDS)
touchled_1.set_color(Color.GREEN)
wait(0.5, SECONDS)
set_fade#
set_fade 改變觸控 LED 過渡到新顏色的方式。
Usage:
touchled_1.set_fade(type)
參數 |
描述 |
|---|---|
|
How fast a color will fade from one to the next:
|
# No fade to red, then slow fade to purple
touchled_1.set_fade(FadeType.OFF)
touchled_1.set_color(Color.RED)
wait(2, SECONDS)
touchled_1.set_fade(FadeType.SLOW)
touchled_1.set_color(Color.PURPLE)
set_brightness#
set_brightness 設定觸摸 LED 的亮度。
Usage:
touchled_1.set_brightness(brightness)
參數 |
描述 |
|---|---|
|
觸控 LED 的亮度可以設定為 0% 到 100% 之間的整數。 |
# Show green at different brightness levels
touchled_1.set_color(Color.GREEN)
wait(1, SECONDS)
touchled_1.set_brightness(10)
wait(1, SECONDS)
touchled_1.set_brightness(100)
set_blink#
set_blink 使觸控 LED 以開啟和關閉的模式反覆閃爍。
注意:呼叫off不會停止閃爍行為。若要停止閃爍行為,請使用set_brightness將LED亮度設為0。
Usage:
set_blink(color, ontime, offtime)
參數 |
描述 |
|---|---|
|
设置触摸 LED 的颜色:
|
|
LED 每次閃爍持續的時間(秒)。預設值為 0.25 秒。 |
|
LED 燈每次閃爍時保持熄滅的時間(秒)。預設值為 0.25 秒。 |
# Blink green for 2 seconds then stop
touchled_1.set_blink(Color.GREEN, 0.5, 0.5)
wait(2, SECONDS)
touchled_1.set_brightness(0)
獲取器#
pressing#
pressing 返回一個整數,指示觸摸 LED 目前是否被按下。
1— 觸摸 LED 正在被按下。0— 觸摸 LED 未被按下。
Usage:
touchled_1.pressing()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
# Turn TouchLED green when touched
while True:
if touchled_1.pressing():
touchled_1.set_color(Color.GREEN)
else:
touchled_1.set_color(Color.RED)
wait(50, MSEC)
installed#
installed 返回一個布林值,指示觸摸 LED 是否連接到大腦。
True— 觸摸 LED 已連接到大腦。False— 觸碰 LED 未連接大腦。
Usage:
touchled_1.installed()
參數 |
描述 |
|---|---|
此方法沒有參數。 |
建構函數#
建構函數用於手動建立 Touchled 對象,這是在 VEXcode 之外配置觸控 LED 所必需的。
Touchled#
Touchled 創建一個觸控 LED。
Usage:
touchled_1 = Touchled(smartport)
範圍 |
描述 |
|---|---|
|
觸摸 LED 連接的智慧型端口,記為 PORTx,其中 x 是端口號。 |
# Create a Touchled in Port 1
touchled_1 = Touchled(Ports.PORT1)