信号塔#
介绍#
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();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The Smart Port that the Signal Tower is connected to, written as |
示例#
// 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 - 注册一个在信号塔保险杠释放时要调用的函数。
setColor#
通过多种输入方式控制信号塔上的 LED 灯颜色和状态。这些灯可用于跟踪机器人在项目中的位置,或显示何时满足特定条件。
Available Functions1 — 使用 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 );
Parameters4 — 分别设置所有 LED 的亮度级别。
void setColor( uint8_t r, uint8_t y, uint8_t g, uint8_t b, uint8_t w );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The color to use:
|
|
|
The state for the LED:
|
|
|
The brightness of red, green and blue LED using a 32-bit value (e.g., red on = |
|
|
The brightness of yellow and white LED using a 32-bit value (e.g., yellow on = |
|
|
The index of the LED to control:
|
|
|
LED 的亮度范围为 0 到 255,其中 0 为关闭,255 为最大亮度。 |
|
|
红色 LED 的亮度范围为 0 到 255,其中 0 为关闭,255 为最大亮度。 |
|
|
黄色 LED 的亮度范围为 0 到 255,其中 0 为关闭,255 为最大亮度。 |
|
|
绿色 LED 的亮度范围为 0 到 255,其中 0 为关闭,255 为最大亮度。 |
|
|
蓝色 LED 的亮度范围为 0 到 255,其中 0 为关闭,255 为最大亮度。 |
|
|
白色 LED 的亮度范围为 0 到 255,其中 0 为关闭,255 为最大亮度。 |
此函数不返回值。
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 Functionsvoid setColors(
signaltower::state rs,
signaltower::state ys,
signaltower::state gs,
signaltower::state bs,
signaltower::state ws );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The state of the red LED:
|
|
|
The state of the yellow LED:
|
|
|
The state of the green LED:
|
|
|
The state of the blue LED:
|
|
|
The state of the white LED:
|
此函数不返回值。
Examples// Turn on all LEDs
SignalTower.setColors(signaltower::on, signaltower::on, signaltower::on, signaltower::on, signaltower::on);
setBlink#
通过 LED 的 ID 设置信号塔上 LED 的闪烁状态。这些闪烁的 LED 可用于指示何时满足特定条件,例如机器人处于等待状态或需要注意时。
Available Functionsvoid setBlink(
ledId id,
bool enable );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The LED ID:
|
|
|
|
此函数不返回值。
setBlinkTime#
设置信号塔上 LED 灯的闪烁间隔时间。
Available Functionsvoid setBlinkTime(
uint32_t onTime,
uint32_t offTime = 0 );
范围 |
类型 |
描述 |
|---|---|---|
|
|
LED闪烁时持续亮起的时间(以毫秒为单位)。最大值为2500毫秒。值为0时,默认值为500毫秒。 |
|
|
LED 闪烁时熄灭的时间(以毫秒为单位)。最大值为 2500 毫秒。值为 0 时使用 onTime 值。默认值为 0。 |
此函数不返回值。
enableBlink#
通过 ID 控制信号塔上多个 LED 灯的闪烁。
Available Functionsvoid enableBlink(
ledId id0,
ledId id1 = ledId::none,
ledId id2 = ledId::none,
ledId id3 = ledId::none,
ledId id4 = ledId::none );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The LED ID:
|
|
|
The index of the second LED (optional). Default is
|
|
|
The index of the third LED (optional). Default is
|
|
|
The index of the fourth LED (optional). Default is
|
|
|
The index of the fifth LED (optional). Default is
|
此函数不返回值。
disableBlink#
通过 ID 禁用信号塔上多个 LED 的闪烁。
Available Functionsvoid disableBlink(
ledId id0,
ledId id1 = ledId::none,
ledId id2 = ledId::none,
ledId id3 = ledId::none,
ledId id4 = ledId::none );
范围 |
类型 |
描述 |
|---|---|---|
|
|
The index of the first LED.
|
|
|
The index of the second LED (optional). Default is
|
|
|
The index of the third LED (optional). Default is
|
|
|
The index of the fourth LED (optional). Default is
|
|
|
The index of the fifth LED (optional). Default is
|
此函数不返回值。
pressing#
返回信号塔的保险杠当前是否被按下。这可以用作紧急停止装置。
Available Functionsbool pressing();
此函数没有参数。
Return Values返回一个布尔值,指示信号塔的保险杠当前是否被按下。
true— The Signal Tower’s bumper is currently being pressed.false— The Signal Tower’s bumper is not being pressed.
pressed#
注册一个在信号塔保险杠被按下时要调用的函数。
Available Functionsvoid pressed( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在按下保险杠时调用。 |
此函数不返回值。
ExamplesDefine 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#
注册一个在信号塔保险杠释放时要调用的函数。
Available Functionsvoid released( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个函数的指针,该函数将在保险杠释放时调用。 |
此函数不返回值。
ExamplesDefine 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); }