数字输入#
初始化digital_in类#
使用以下构造函数创建数字输入:
The digital_in constructor creates a digital_in object in the specified Three Wire Port:
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Digital Input is connected to, whether it’s a port on the |
A Brain or 3-Wire Expander must be created first before they can be used to create an object with the digital_in Class constructor.
// Create the Brain.
brain Brain;
// Construct a Digital Input "digin" with the
// digital_in class.
digital_in digin = digital_in(Brain.ThreeWirePort.A);
This digin object will be used in all subsequent examples throughout this API documentation when referring to digital_in class methods.
类方法#
high()#
The high(callback) method registers a callback function to be called when the Digital Input is high.
参数 |
描述 |
|---|---|
|
当输入为高时将被调用的函数。 |
**返回:**事件类的一个实例。
// Define the inputHigh function with a void return
// type, showing it doesn't return a value.
void inputHigh() {
// The Brain will print that the Digital Input is high
// on the Brain's screen.
Brain.Screen.print("digital input high");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run inputHigh when the Digital Input is high.
digin.high(inputHigh);
}
low()#
The low(callback) method registers a callback function to be called when the Digital Input is low.
参数 |
描述 |
|---|---|
|
当输入为低时将调用的函数。 |
**返回:**事件类的一个实例。
// Define the inputLow function with a void return type,
// showing it doesn't return a value.
void inputLow() {
// The Brain will print that the Digital Input is low
// on the Brain's screen.
Brain.Screen.print("digital input low");
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Run inputLow when the Digital Input is low.
digin.low(inputLow);
}