Signal Tower#

Introduction#

The signaltower class is used to change lights and detect interactions with the CTE Signal Tower.

Class Constructors#

signaltower( 
  int32_t  index );

Class Destructor#

Destroys the signaltower object and releases associated resources.

virtual ~signaltower();

Parameters#

Parameter

Type

Description

index

int32_t

The Smart Port that the Signal Tower is connected to, written as PORTx, where x is the port number (for example, PORT1).

Examples#

// Create a signal tower instance in Port 1
signaltower SignalTower = signaltower(PORT1);

Member Functions#

The signaltower class provides the following member functions:

  • setColor - Controls the LED colors and states on the Signal Tower using various input methods.

  • setColors - Sets the state of all LEDs on the Signal Tower individually.

  • setBlink - Sets the blink state of an LED on the Signal Tower by the LED’s ID.

  • setBlinkTime - Sets the time between blinks for the LEDs on the Signal Tower.

  • enableBlink - Enables blinking for multiple LEDs on the Signal Tower by their IDs.

  • disableBlink - Disables blinking for multiple LEDs on the Signal Tower by their IDs.

  • pressing - Returns whether the Signal Tower bumper is currently being 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.

setColor#

Controls the LED colors and states on the Signal Tower using various input methods. These lights can be used to track where the robot is at in a project or to show when certain conditions are met.

Available Functions

1 Sets the Signal Tower to a color using vex::color.

void setColor( 
  vex::color         color, 
  signaltower::state state = signaltower::state::on );

2 Sets LED colors using 32-bit RGB and YW values.

void setColor( 
  uint32_t rgb, 
  uint32_t yw );

3 Sets individual LED brightness by LED ID.

void setColor( 
  ledId id, 
  uint32_t value );

4 Sets brightness levels for all LEDs individually.

void setColor( 
  uint8_t r, 
  uint8_t y, 
  uint8_t g, 
  uint8_t b, 
  uint8_t w );

Parameters

Parameter

Type

Description

color

vex::color

The color to use:

  • red
  • yellow
  • green
  • blue
  • white
  • all

state

signaltower::state

The state for the LED:

  • on (Default) – Turns the LED on.
  • off – Turns the LED off.
  • blink – Makes the LED blink.

rgb

uint32_t

The brightness of red, green and blue LED using a 32-bit value (e.g., red on = 0xFF0000, green on = 0x00FF00, and blue on = 0x0000FF).

yw

uint32_t

The brightness of yellow and white LED using a 32-bit value (e.g., yellow on = 0xFF00 and white on = 0x00FF).

id

ledId

The index of the LED to control:

  • 0 – red
  • 1 – green
  • 2 – blue
  • 3 – white
  • 4 – yellow

value

uint32_t

The brightness of the LED from 0 to 255, with 0 being off and 255 being the max brightness.

r

uint8_t

The brightness of the red LED from 0 to 255, with 0 being off and 255 being the max brightness.

y

uint8_t

The brightness of the yellow LED from 0 to 255, with 0 being off and 255 being the max brightness.

g

uint8_t

The brightness of the green LED from 0 to 255, with 0 being off and 255 being the max brightness.

b

uint8_t

The brightness of the blue LED from 0 to 255, with 0 being off and 255 being the max brightness.

w

uint8_t

The brightness of the white LED from 0 to 255, with 0 being off and 255 being the max brightness.

Return Values

This function does not return a value.

Examples
// Set the Signal Tower to start blinking blue
SignalTower.setColor(vex::color::blue, signaltower::blink);

// Set the red, blue and white LEDs using hex values
SignalTower.setColor(0xFF00FF, 0x00FF);

// Set the green LED to full brightness by ID
SignalTower.setColor(1, 255);

// Set all LEDs to full brightness
SignalTower.setColor(255, 255, 255, 255, 255);

setColors#

Sets the state of all LEDs on the Signal Tower individually. These lights can be used to track where the robot is at in a project or to show when certain conditions are met.

Available Functions
void setColors( 
  signaltower::state rs, 
  signaltower::state ys, 
  signaltower::state gs, 
  signaltower::state bs, 
  signaltower::state ws );

Parameters

Parameter

Type

Description

rs

signaltower::state

The state of the red LED:

  • on – Turns the LED on.
  • off – Turns the LED off.
  • blink – Makes the LED blink.

ys

signaltower::state

The state of the yellow LED:

  • on – Turns the LED on.
  • off – Turns the LED off.
  • blink – Makes the LED blink.

gs

signaltower::state

The state of the green LED:

  • on – Turns the LED on.
  • off – Turns the LED off.
  • blink – Makes the LED blink.

bs

signaltower::state

The state of the blue LED:

  • on – Turns the LED on.
  • off – Turns the LED off.
  • blink – Makes the LED blink.

ws

signaltower::state

The state of the white LED:

  • on – Turns the LED on.
  • off – Turns the LED off.
  • blink – Makes the LED blink.

Return Values

This function does not return a value.

Examples
// Turn on all LEDs
SignalTower.setColors(signaltower::on, signaltower::on, signaltower::on, signaltower::on, signaltower::on);

setBlinkTime#

Sets the time between blinks for the LEDs on the Signal Tower.

Available Functions
void setBlinkTime( 
  uint32_t onTime, 
  uint32_t offTime = 0 );

Parameters

Parameter

Type

Description

onTime

uint32_t

The time in milliseconds that the LED should be on when blinking. Max is 2500ms. A value of 0 defaults to 500ms.

offTime

uint32_t

The time in milliseconds that the LED should be off when blinking. Max is 2500ms. A value of 0 uses the onTime value. Default is 0.

Return Values

This function does not return a value.

pressing#

Returns whether the Signal Tower’s bumper is currently being pressed. This can be used as an emergency stop.

Available Functions
bool pressing();

Parameters

This function does not have parameters.

Return Values

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.

pressed#

Registers a function to be called when the Signal Tower bumper is pressed.

Available Functions
void pressed( void (* callback)(void) );

Parameters

Parameter

Type

Description

callback

void (*)(void)

A pointer to a function that will be called when the bumper is pressed.

Return Values

This function does not return a value.

Examples

Define the callback function (outside of int main())

// Display a message when bumper is pressed
void towerBumperPressed() {
  Brain.Screen.print("tower bumper pressed");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run towerBumperPressed when the tower bumper 
  // is pressed
  SignalTower.pressed(towerBumperPressed);
}

released#

Registers a function to be called when the Signal Tower bumper is released.

Available Functions
void released( void (* callback)(void) );

Parameters

Parameter

Type

Description

callback

void (*)(void)

A pointer to a function that will be called when the bumper is released.

Return Values

This function does not return a value.

Examples

Define the callback function (outside of int main())

// Display a message when bumper is pressed
void towerBumperReleased() {
  Brain.Screen.print("tower bumper pressed");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run towerBumperReleased when the tower bumper 
  // is released
  SignalTower.pressed(towerBumperReleased);
}