信号塔#
初始化信号塔类#
使用以下构造函数创建信号塔:
signaltower
构造函数创建一个 signaltower 对象。
范围 |
描述 |
---|---|
|
SignalTower 连接到的有效 智能端口。 |
// Construct a Signal Tower "SignalTower" with the
// signaltower class.
signaltower SignalTower = signaltower(PORT1);
当引用 signaltower 类方法时,此 SignalTower
对象将在整个 API 文档的所有后续示例中使用。
类方法#
设置颜色()#
该方法通过以下方式调用:
setColor(color, state)
方法使用预定义颜色或十六进制代码打开或关闭信号塔上的一个或多个 LED。
范围 |
描述 |
---|---|
颜色 |
有效的 signalTowerColorType、colorType 或十六进制代码。 |
状态 |
有效的 signalTowerStateType。 |
**返回:**无。
// Set the Signal Tower to start blinking blue.
SignalTower.setColor(signaltower::blue, signaltower::blink);
setColor(rgb, yx)
方法使用 32 位值打开或关闭信号塔上的一个或多个 LED。
范围 |
描述 |
---|---|
RGB |
代表红色、绿色和蓝色 LED 亮度的十六进制值。 |
yw |
代表黄色和白色 LED 亮度的十六进制值。 |
**返回:**无。
// Set the red, blue and white LEDs to on.
// 0xFF00FF sets the red and blue LEDs on
SignalTower.setColor(0xFF00FF, 0x00FF);
setColor(id, value)
方法根据 LED 的 id 打开或关闭信号塔上的 LED。
LED 编号:
红色:0
绿色:1
蓝色:2
白色:3
黄色:4
无:99
范围 |
描述 |
---|---|
ID |
信号塔上其中一个 LED 的 ID。 |
价值 |
LED 的亮度值在 0 - 255 范围内。 |
**返回:**无。
// Set the green LEDs to on.
SignalTower.setColor(1, 255);
setColor(r, y, g, b, w)
方法设置信号塔上每个 LED 的亮度级别。
范围 |
描述 |
---|---|
r |
LED 的亮度值在 0 - 255 范围内。 |
y |
LED 的亮度值在 0 - 255 范围内。 |
克 |
LED 的亮度值在 0 - 255 范围内。 |
b |
LED 的亮度值在 0 - 255 范围内。 |
西 |
LED 的亮度值在 0 - 255 范围内。 |
**返回:**无。
// Set all LEDs to on.
SignalTower.setColor(255, 255, 255, 255, 255);
设置颜色()#
setColors(r, y, g, b, w)
方法打开或关闭信号塔上的所有 LED。
范围 |
描述 |
---|---|
r |
用于设置红色 LED 的有效 signalTowerStateType。 |
y |
用于将黄色 LED 设置为有效的 signalTowerStateType。 |
克 |
有效的 signalTowerStateType,用于将 LED 设置为绿色。 |
b |
用于设置蓝色 LED 的有效 signalTowerStateType。 |
西 |
用于设置白色 LED 的有效 signalTowerStateType。 |
**返回:**无
// Turn on all LEDs.
SignalTower.setColors(signaltower::on, signaltower::on, signaltower::on, signaltower::on, signaltower::on);
设置闪烁()#
setBlink(id, enable)
方法通过 LED 的 id 设置信号塔上 LED 的闪烁状态。
LED 编号:
红色:0
绿色:1
蓝色:2
白色:3
黄色:4
无:99
范围 |
描述 |
---|---|
ID |
您要设置闪烁状态的 LED 的 ID。 |
使能够 |
用于将 LED 设置为闪烁还是不闪烁的布尔值。 |
**返回:**无。
设置闪烁时间()#
setBlinkTime(onTime, offTime)
方法设置信号塔上 LED 的闪烁时间。
范围 |
描述 |
---|---|
准时 |
LED 闪烁时亮起的持续时间(以毫秒为单位)。最大值为 2500 毫秒。值为 0 时默认为 500 毫秒。 |
关机时间 |
LED 闪烁时应关闭的时间(以毫秒为单位)。最大值为 2500 毫秒。值为 0 时将使用 onTime 的设置时间。默认值为 0。 |
**返回:**无。
启用闪烁()#
enableBlink(id0, id1, id2, id3, id4)
方法通过 LED 的 id 将信号塔上的 LED 设置为闪烁状态。
LED 编号:
红色:0
绿色:1
蓝色:2
白色:3
黄色:4
无:99
范围 |
描述 |
---|---|
id0 |
您想要将其闪烁状态设置为开的第一个 LED 的 ID。 |
ID1 |
您想要将其闪烁状态设置为开的第一个 LED 的 ID。 |
ID2 |
您想要将其闪烁状态设置为开的第一个 LED 的 ID。 |
ID3 |
您想要将其闪烁状态设置为开的第一个 LED 的 ID。 |
ID4 |
您想要将其闪烁状态设置为开的第一个 LED 的 ID。 |
**返回:**无。
disableBlink()#
disableBlink(id0, id1, id2, id3, id4)
方法通过 LED 的 id 将信号塔上的 LED 的闪烁状态设置为关闭。
LED 编号:
红色:0
绿色:1
蓝色:2
白色:3
黄色:4
无:99
范围 |
描述 |
---|---|
id0 |
您想要将闪烁状态设置为关闭的第一个 LED 的 ID。 |
ID1 |
您想要将闪烁状态设置为关闭的第一个 LED 的 ID。 |
ID2 |
您想要将闪烁状态设置为关闭的第一个 LED 的 ID。 |
ID3 |
您想要将闪烁状态设置为关闭的第一个 LED 的 ID。 |
ID4 |
您想要将闪烁状态设置为关闭的第一个 LED 的 ID。 |
**返回:**无。
紧迫()#
pressing()
方法返回信号塔按钮当前是否被按下。
**返回:**如果当前按下信号塔按钮,则返回 true
。如果不是,则返回 false
。
按下()#
pressed(callback)
方法注册一个当按下信号塔按钮时要调用的函数。
范围 |
描述 |
---|---|
打回来 |
按下按钮时调用的函数 |
**返回:**无。
// 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");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run towerButtonPressed when the tower button
// is pressed.
SignalTower.pressed(towerButtonPressed);
}
发布()#
released(callback)
方法注册一个在信号塔按钮被释放时调用的函数。
范围 |
描述 |
---|---|
打回来 |
释放按钮时调用的函数 |
**返回:**无。
// 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");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run towerButtonReleased when the tower
// button is released.
SignalTower.released(towerButtonReleased);
}
时间戳()#
timestamp()
方法请求信号塔最后收到的状态包的时间戳。
**返回:**最后一个状态包的时间戳,以毫秒为单位的无符号 32 位整数。
安装()#
installed()
方法返回信号塔是否已连接。
**返回:**如果设备已连接,则返回 true
。如果未连接,则返回 false
。