LED保险杠#
介绍#
LED 保险杠可以改变其 LED 的颜色并检测何时被按下。
For the examples below, the configured LED Bumper will be named bumper
. They will be used in all subsequent examples throughout this API documentation when referring to LEDBumper
class methods.
以下是所有方法的列表:
改变器——改变颜色和亮度。
set_color
– Set the color of the LED Bumper.set_brightness
– Set the brightness of the LED Bumper.
Getters – 从 LED 保险杠返回数据。
is_pressed
– Returns whether or not the LED Bumper is being pressed.
修改器#
set_color#
set_color
设置 LED 保险杠的颜色。如果使用此方法时 LED 尚未亮起,则会将亮度设置为 100% 以打开 LED。
Usage:
bumper.set_color(color)
参数 |
描述 |
---|---|
|
LED 保险杠的颜色设置:
|
# Build Used: Super Code Base 2.0
def main():
# Blink the LED off and on
while True:
bumper.set_color(GREEN)
wait(0.5, SECONDS)
bumper.set_color(OFF)
wait(0.5, SECONDS)
# Start threads — Do not delete
start_thread(main)
set_brightness#
set_brightness
设置 LED 保险杠的亮度。
Usage:
bumper.set_brightness(color)
参数 |
描述 |
---|---|
|
LED 的亮度以百分比表示,范围从 0% 到 100%。 |
# Build Used: Super Code Base 2.0
def main():
# Light up the LED at different brightnesses
bumper.set_brightness(25)
bumper.set_color(GREEN)
wait(2, SECONDS)
bumper.set_brightness(100)
# Start threads — Do not delete
start_thread(main)
盖特#
is_pressed#
is_pressed
returns a Boolean indicating whether or not the LED Bumper is pressed.
True
– 保险杠被压下。False
– 保险杠未被按下。
Usage:
bumper.is_pressed()
参数 |
描述 |
---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Turn right when the bumper is pressed
drivetrain.turn(LEFT)
while not bumper.is_pressed():
wait(0.2, SECONDS)
drivetrain.turn(RIGHT)
# Start threads — Do not delete
start_thread(main)