LED保险杠#
介绍#
LED 保险杠可以改变其 LED 的颜色并检测何时被按下。
For the examples below, the configured LED Bumper will be named bumper. This name is used in all subsequent examples throughout this API documentation when referring to LEDBumper class methods.
以下是所有方法的列表:
Mutators — Change colors and brightness.
set_color— Set the color of the LED Bumper.set_brightness— Set the brightness of the LED Bumper.
Getters — Return data from the LED Bumper.
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)
参数 |
描述 |
|---|---|
|
The color to set the LED Bumper to:
|
# 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 brightness levels
bumper.set_brightness(25)
bumper.set_color(GREEN)
wait(2, SECONDS)
bumper.set_brightness(100)
# Start threads — Do not delete
start_thread(main)
Getters#
is_pressed#
is_pressed returns a Boolean indicating whether or not the LED Bumper is pressed.
True— The bumper is pressed.False— The bumper is not pressed.
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)