信号塔#
介绍#
The Signal Tower is a device that uses colored lights to show the robot’s status. It also has a built-in bumper switch that can detect when it is pressed.
For the examples below, the configured Signal Tower will be named signal_tower_1 and will be used in all subsequent examples throughout this API documentation when referring to SignalTower class methods.
以下是所有可用方法的列表:
设置人员——配置信号塔灯光的颜色和模式。
set_color– Sets the pattern for one or all Signal Tower LEDs.set_colors– Sets the state of each Signal Tower LED.
Getters – 请阅读信号塔保险杠的状态说明。
pressing– Returns whether the Signal Tower bumper is currently pressed.
回调函数 – 当信号塔保险杠状态改变时运行代码。
pressed– Registers a function to be called when the Signal Tower bumper is pressed.released– Registers a function to be called when the Signal Tower bumper is released.
建造者 – 手动初始化和配置信号塔。
SignalTower– Create a Signal Tower.
二传手#
set_color#
set_color sets the light pattern of one or all LEDs on the Signal Tower. These lights can be used to track where the robot is at in a project or to show when certain conditions are met.
Usage:
signal_tower_1.set_color(value, state)
范围 |
描述 |
|---|---|
价值 |
The color light to control:
|
状态 |
The light pattern to apply:
|
# Set the Signal Tower to start blinking the blue LED
signal_tower_1.set_color(SignalTower.BLUE, signal_tower.BLINK)
set_colors#
set_colors sets the state of each Signal Tower LED. These lights can be used to track where the robot is at in a project or to show when certain conditions are met.
Usage:
signal_tower_1.set_colors(r, y, g, b, w)
范围 |
描述 |
|---|---|
r |
The state for the red light:
|
是 |
The state for the yellow light:
|
克 |
The state for the green light:
|
b |
The state for the blue light:
|
西 |
The state for the white light:
|
# Turn on all LEDs
signal_tower_1.set_colors(SignalTower.ON, SignalTower.ON, SignalTower.ON, SignalTower.ON, SignalTower.ON)
# Turn on just the red LED
signal_tower_1.set_colors(SignalTower.ON, SignalTower.OFF, SignalTower.OFF, SignalTower.OFF, SignalTower.OFF)
获取器#
pressing#
pressing returns a Boolean indicating whether the Signal Tower’s bumper is currently being pressed. This can be used as an emergency stop.
True— The Signal Tower’s bumper is currently being pressed.False— The Signal Tower’s bumper is not being pressed.
Usage:
signal_tower_1.pressing()
回调函数#
pressed#
pressed registers a function to be called when the Signal Tower’s bumper is pressed.
This method returns an instance of the Event class.
Usage:
signal_tower_1.pressed(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数,当信号塔的保险杠被按下时执行。 |
|
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
# Define a function tower_button_pressed()
def tower_button_pressed():
# Print that the Signal Tower's button was pressed
# to the Brain's screen.
brain.screen.print("button pressed")
# Run tower_button_pressed when the Signal Tower's
# button is pressed.
signal_tower_1.pressed(tower_button_pressed)
released#
released registers a function to be called when the Signal Tower’s bumper is released.
This method returns an instance of the Event class.
Usage:
signal_tower_1.released(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数,当信号塔的保险杠被释放时执行。 |
|
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
# Define a function tower_button_released()
def tower_button_released():
# Print that the Signal Tower's button was released
# to the Brain's screen.
brain.screen.print("button released")
# Run tower_button_released when the Signal Tower's
# button is released.
signal_tower_1.released(tower_button_released)
构造函数#
SignalTower#
SignalTower creates a Signal Tower.
SignalTower(smartport)
范围 |
描述 |
|---|---|
|
The Smart Port that the Signal Tower is connected to, written as |
# Construct a Signal Tower "signal_tower_1" with the
# SignalTower class
signal_tower_1 = SignalTower(Ports.PORT1)