Signal Tower#
Introduction#
The Signal Tower is an indicator device that provides visual status feedback using colored lights and includes a built-in bumper switch for detecting physical interaction.
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.
Below is a list of all available methods:
Setters – Configure the Signal Tower light colors and patterns.
set_color– Sets the pattern for a single Signal Tower color band.set_colors– Sets the state of each Signal Tower light band.
Getters – Read the state of the Signal Tower bumper.
pressing– Returns whether the Signal Tower bumper is currently pressed.
Callbacks – Run code when the Signal Tower bumper state changes.
pressed– Calls a function when the Signal Tower bumper is pressed.released– Calls a function when the Signal Tower bumper is released.
Constructors – Manually initialize and configure the Signal Tower.
SignalTower– Create a Signal Tower.
Setters#
set_color#
set_color sets the light pattern of one or more color lights on the Signal Tower.
Usage:
signal_tower_1.set_color(value, state)
范围 |
描述 |
|---|---|
value |
Optional. The color light to control:
|
state |
Optional. 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 light band.
Usage:
signal_tower_1.set_colors(r, y, g, b, w)
范围 |
描述 |
|---|---|
r |
The state for the red LED:
|
y |
The state for the yellow LED:
|
g |
The state for the green LED:
|
b |
The state for the blue LED:
|
w |
The state for the white LED:
|
# 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)
Getters#
pressing#
pressing returns a Boolean indicating whether the Signal Tower’s bumper is currently being pressed.
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()
Callbacks#
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)
Parameters |
描述 |
|---|---|
|
A previously defined function that executes when the Signal Tower’s bumper is pressed. |
|
Optional. A tuple containing arguments to pass to the callback function. See Using 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)
Parameters |
描述 |
|---|---|
|
A previously defined function that executes when the Signal Tower’s bumper is released. |
|
Optional. A tuple containing arguments to pass to the callback function. See Using 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)
Constructors#
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)