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.

以下是所有方法的列表:

变异器——改变颜色和亮度。

获取器 — 返回来自 LED 保险杠的数据。

  • is_pressed — Returns whether or not the LED Bumper is being pressed.

修改器#

set_color#

set_color sets the color of the LED Bumper, or turns it off.

LED 可以用来跟踪机器人在项目中的位置,或者显示何时满足某些条件。

LED 保险杠可用于跟踪机器人在项目中的位置,或显示何时满足某些条件。

Usage:
bumper.set_color(color)

参数

描述

color

The color to set the LED Bumper to:

  • GREEN
  • OFF — Turns off the LED
  • RED

# 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 sets how bright the LED Bumper is.

百分比越高,灯光越亮;百分比越低,灯光越暗。

如果 LED 保险杠灯关闭,将灯光功率设置为 0% 以上即可打开灯光。

如果 LED 保险杠灯亮着,将灯光功率设置为 0% 将关闭灯光。

百分比越高,灯光越亮;百分比越低,灯光越暗。

如果 LED 保险杠灯关闭,将灯光功率设置为 0% 以上即可打开灯光。

如果 LED 保险杠灯亮着,将灯光功率设置为 0% 将关闭灯光。

Usage:
bumper.set_brightness(color)

参数

描述

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)

获取器#

is_pressed#

is_pressed returns a Boolean indicating whether or not the LED Bumper is pressed. This can be used to check if the robot bumps into other objects.

  • True — The LED Bumper is pressed.

  • False — The LED 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)