Signal Tower#
Introduction#
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.
Below is a list of all available methods:
Setters – Configure the Signal Tower light colors and patterns.
set_color– Sets the pattern for one or all Signal Tower LEDs.set_colors– Sets the state of each Signal Tower LED.
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– 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.
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 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)
Parameter |
Description |
|---|---|
value |
The color light to control:
|
state |
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)
Parameter |
Description |
|---|---|
r |
The state for the red light:
|
y |
The state for the yellow light:
|
g |
The state for the green light:
|
b |
The state for the blue light:
|
w |
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)
Getters#
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()
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 |
Description |
|---|---|
|
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 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 |
Description |
|---|---|
|
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 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)
Parameter |
Description |
|---|---|
|
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)