触摸LED#
介绍#
触摸 LED 是一种电容式触摸按钮,可以以不同的亮度级别和转换速度显示颜色,并可以检测何时按下。
For the examples below, the configured Touch LED will be named touchled_1 and will be used in all subsequent examples throughout this API documentation when referring to Touchled class methods.
以下是所有方法的列表:
操作——与触摸 LED 交互。
pressed– Calls a function when the Touch LED is pressed.released– Calls a function when the Touch LED is released.on– Turns the Touch LED on.off– Turns the Touch LED off.toggle– Turns the Touch LED on or off.
改变器——改变触摸 LED 的颜色、亮度和设置。
set_color– Sets the color of the Touch LED.set_fade– Sets how fast colors will fade to one another.set_brightness– Sets the brightness of the Touch LED.vset_blink – Alternate the Touch LED on and off indefinitely.
Getters – 从触摸 LED 返回数据。
pressing– Returns whether the Touch LED is being pressed.installed– Returns whether the Touch LED is connected to the Brain.
构造函数——手动初始化和配置触摸 LED。
Touchled– Create a Touch LED.
行动#
pressed#
pressed registers a function to be called when the Touch LED is pressed.
Usage:
touchled_1.pressed(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的当触摸 LED 被按下时执行的功能。 |
|
可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数](…/Logic/Functions.md#functions-with-parameters)。 |
# Turn blue while the Touch LED is pressed
def light_blue():
touchled_1.set_color(Color.BLUE)
touchled_1.pressed(light_blue)
released#
released registers a function to be called when the Touch LED is released.
Usage:
touchled_1.released(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的在触摸 LED 释放时执行的功能。 |
|
可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数](…/Logic/Functions.md#functions-with-parameters)。 |
# Turn red when the Touch LED is released
def light_red():
touchled_1.set_color(Color.RED)
touchled_1.released(light_red)
on#
on turns the Touch LED on by setting its brightness to 100%.
Usage:
touchled_1.on(value)
参数 |
描述 |
|---|---|
|
Optional. Sets the LED’s color to:
|
# Turn green when the robot is moving
touchled_1.on(Color.GREEN)
drivetrain.drive_for(FORWARD, 5)
touchled_1.off()
off#
off turns the Touch LED off by setting its brightness to 0%.
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 turns the Touch LED on or off. If the LED is currently on, toggle sets its brightness to 0%, turning it off. If the LED is off, toggle sets its brightness to 100%, turning it on.
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 sets the color of the Touch LED. If the Touch LED is not already on when this method is used, it will set the brightness to 100% to turn the Touch LED on.
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 changes the color fade setting for the Touch 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 sets the brightness of the Touch LED.
Usage:
touchled_1.set_brightness(brightness)
参数 |
描述 |
|---|---|
|
触摸 LED 的亮度设置为百分比。 |
# 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 repeatedly blinks the TouchLED in an on and off pattern.
Note: Calling off will not stop the blinking behavior. To stop the blinking behavior, set the LED brightness to 0 with set_brightness.
Usage:
set_blink(color, ontime, offtime)
参数 |
描述 |
|---|---|
|
Sets the Touch LED’s color to:
|
|
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 returns an integer indicating whether the Touch LED is currently being pressed.
1- The TouchLED is being pressed.0- The TouchLED is not being pressed.
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 returns a Boolean indicating whether the Touch LED is connected to the Brain.
True- The Touch LED is connected to the Brain.False- The Touch LED is not connected to the Brain.
Usage:
touchled_1.installed()
参数 |
描述 |
|---|---|
该方法没有参数。 |
构造函数#
Constructors are used to manually create Touchled objects, which are necessary for configuring a Touch LED outside of VEXcode.
Touchled#
Touchled creates a Touch LED.
Usage:
touchled_1 = Touchled(port)
范围 |
描述 |
|---|---|
|
Which Smart Port that the Touch LED is connected to as |
# Create a Touchled in Port 1
touchled_1 = Touchled(Ports.PORT1)