Ψηφιακή είσοδος#
Εισαγωγή#
The digital_in class allows the V5 Brain to read a digital signal from an external source, such as a switch or sensor. It detects whether the input line is high, receiving 5 volts, or low, receiving 0 volts. This can be used to determine on/off states or trigger events in a project.
Κατασκευαστές κλάσεων#
digital_in(
triport::port &port );
Καταστροφέας κλάσης#
Destroys the digital_in object and releases associated resources.
~digital_in();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The 3-Wire Port that the Digital Input device is connected to, written as |
Παράδειγμα#
// Create the digital_in instance on 3-Wire Port A
digital_in digin = digital_in(Brain.ThreeWirePort.A);
Συναρτήσεις Μελών#
The digital_in class includes the following member functions:
value— Returns whether the Digital In port is receiving a high or low signal.high— Registers a function to be called whenever the Digital In device sends a high signal.low— Registers a function to be called whenever the Digital In device sends a low signal.
Before calling any digital_in member functions, a digital_in instance must be created, as shown below:
/* 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();
Παράμετροι
Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.
Επιστρεφόμενες τιμές
Returns an int32_t representing the current digital signal state:
1– The Digital In port is receiving a high signal (approximately 5V).0– The Digital In port is receiving a low signal (approximately 0V).
high#
Καταγράφει μια λειτουργία που θα καλείται κάθε φορά που η συσκευή Digital In στέλνει υψηλό σήμα (περίπου 5V).
Available Functionsvoid high(
void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια συνάρτηση που θα καλείται όταν η είσοδος είναι υψηλή. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesDefine the callback function (outside of
int main())// Display that the input is high void inputHigh() { Brain.Screen.print("digital input high"); }Register the callback inside
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) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια συνάρτηση που θα καλείται όταν η είσοδος είναι χαμηλή. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesDefine the callback function (outside of
int main())// Display that the input is low void inputLow() { Brain.Screen.print("digital input low"); }Register the callback inside
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); }