信号塔#

介绍#

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

类构造函数#

signaltower( 
  int32_t  index );

类析构函数#

Destroys the signaltower object and releases associated resources.

virtual ~signaltower();

参数#

范围

类型

描述

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).

示例#

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

成员功能#

The signaltower class provides the following member functions:

  • setColor - 使用各种输入方法控制信号塔上的 LED 颜色和状态。

  • setColors - 分别设置信号塔上所有 LED 的状态。

  • setBlink - 根据 LED 的 ID 设置信号塔上 LED 的闪烁状态。

  • setBlinkTime - 设置信号塔上 LED 的闪烁时间。

  • enableBlink - 启用信号塔上多个 LED 的闪烁功能,并指定它们的 ID。

  • disableBlink - 根据 ID 禁用信号塔上多个 LED 的闪烁。

  • pressing - 返回信号塔按钮当前是否被按下。

  • pressed - 注册一个在信号塔按钮被按下时要调用的函数。

  • released - 注册一个在信号塔按钮释放时要调用的函数。

  • timestamp - 返回从信号塔接收到的最后一个状态数据包的时间戳。

  • installed - 返回信号塔设备是否已连接。

setColor#

通过各种输入方式控制信号塔上的 LED 颜色和状态。

Available Functions

1 使用 vex::color 将信号塔设置为某种颜色。

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

2 使用 32 位 RGB 和 YW 值设置 LED 颜色。

void setColor( 
  uint32_t rgb, 
  uint32_t yw );

3 根据 LED ID 设置单个 LED 的亮度。

void setColor( 
  ledId id, 
  uint32_t value );

4 分别设置所有 LED 的亮度级别。

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

Parameters

范围

类型

描述

color

vex::color

The color to use (red, green, etc.) using vex::color.

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 32-bit value (e.g., red on = 0xFF0000).

yw

uint32_t

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

id

ledId

要控制的LED的索引。

value

uint32_t

LED 的亮度(0 到 255)。

r

uint8_t

红色 LED 的亮度(0 到 255)。

y

uint8_t

黄色 LED 的亮度(0 到 255)。

g

uint8_t

绿色 LED 的亮度(0 到 255)。

b

uint8_t

蓝色 LED 的亮度(0 到 255)。

w

uint8_t

白色 LED 的亮度(0 到 255)。

Return Values

此函数不返回值。

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#

分别设置信号塔上所有 LED 的状态。

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

Parameters

范围

类型

描述

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

此函数不返回值。

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

setBlinkTime#

设置信号塔上 LED 灯的闪烁时间。

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

Parameters

范围

类型

描述

onTime

uint32_t

LED闪烁时持续亮起的时间(以毫秒为单位)。最大值为2500毫秒。值为0时,默认值为500毫秒。

offTime

uint32_t

LED 闪烁时熄灭的时间(以毫秒为单位)。最大值为 2500 毫秒。值为 0 时使用 onTime 值。默认值为 0。

Return Values

此函数不返回值。

pressing#

返回信号塔按钮当前是否被按下。

Available Functions
bool pressing();

Parameters

此函数没有参数。

Return Values

返回一个布尔值,指示信号塔按钮当前是否被按下。

  • true if the signal tower button is currently being pressed.

  • false if the signal tower button is not currently being pressed.

pressed#

注册一个在信号塔按钮被按下时要调用的函数。

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

Parameters

范围

类型

描述

callback

void (*)(void)

按钮按下时将调用的函数。

Return Values

此函数不返回值。

Examples
// Define the towerButtonPressed function with a void 
// return type, showing it doesn't return a value.
void towerButtonPressed() {
  // The Brain will print that the tower button was
  // pressed on the Brain's screen.
  Brain.Screen.print("tower button pressed");
}

// Run towerButtonPressed when the tower button 
// is pressed.
SignalTower.pressed(towerButtonPressed);

released#

注册一个在信号塔按钮释放时要调用的函数。

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

Parameters

范围

类型

描述

callback

void (*)(void)

按钮释放时将调用的函数。

Return Values

此函数不返回值。

Examples
// Define the towerButtonReleased function with a void 
// return type, showing it doesn't return a value.
void towerButtonReleased() {
  // The Brain will print that the tower button was 
  // released on the Brain's screen.
  Brain.Screen.print("tower button released");
}

// Run towerButtonReleased when the tower 
// button is released.
SignalTower.released(towerButtonReleased);

timestamp#

返回从信号塔接收到的最后一个状态数据包的时间戳。

Available Functions
uint32_t timestamp();

Parameters

此函数没有参数。

Return Values

Returns the timestamp of the last status packet as a uint32_t in milliseconds since the last status packet was received.

installed#

返回信号塔是否已连接。

Available Functions
bool installed();

Parameters

此函数没有参数。

Return Values

返回一个布尔值,指示信号塔是否已连接。

  • true if the signal tower is connected.

  • false if the signal tower is not connected.