数字输入#
介绍#
V5 Brain 的 digital_in 类允许其读取来自外部源(例如开关或传感器)的数字信号。它会检测输入线是高电平(接收到 5 伏电压)还是低电平(接收到 0 伏电压)。这可用于确定开/关状态或触发项目中的事件。
类构造函数#
digital_in(
triport::port &port );
类析构函数#
销毁 digital_in 对象并释放相关资源。
~digital_in();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
数字输入设备连接的 3 线端口,写成 |
例子#
// Create the digital_in instance on 3-Wire Port A
digital_in digin = digital_in(Brain.ThreeWirePort.A);
成员功能#
数字输入类 digital_in 函数:
value— 返回数字输入端口是否接收到高电平或低电平信号。high— 注册一个函数,当数字输入设备发送高信号时,该函数将被调用。low— 注册一个函数,当数字输入设备发送低信号时,该函数将被调用。
在调用任何 digital_in 函数之前,必须先创建一个 digital_in ,如下所示:
/* This constructor is required when using VS Code.
Digital input configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the digital_in instance on 3-Wire Port A
digital_in DigitalInA = digital_in(Brain.ThreeWirePort.A);
value#
返回数字输入端口接收到的是高电平信号还是低电平信号。
可用功能
int32_t value();
参数
此函数不接受任何参数。
返回值
返回一个表示当前数字信号状态的 int32_t:
1– 数字输入端口接收到高电平信号(约 5V)。0– 数字输入端口接收到低信号(大约 0V)。
high#
注册一个函数,当数字输入设备发送高电平信号(约 5V)时,该函数将被调用。
Available Functionsvoid high(
void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
当输入为高电平时将调用的函数。 |
此函数不返回值。
Examples定义回调函数(在
int main()之外)// Display that the input is high void inputHigh() { Brain.Screen.print("digital input high"); }在
int main()中注册回调函数int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run inputHigh when the Digital Input is high DigitalInA.high(inputHigh); }
low#
注册一个函数,当数字输入设备发送低信号(约 0V)时,该函数将被调用。
Available Functionsvoid low(
void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
当输入为低电平时将调用的函数。 |
此函数不返回值。
Examples定义回调函数(在
int main()之外)// Display that the input is low void inputLow() { Brain.Screen.print("digital input low"); }在
int main()中注册回调函数int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run inputLow when the Digital Input is low DigitalInA.low(inputLow); }