Αναλογική είσοδος#
Εισαγωγή#
The analog_in class is used to read analog input signals from devices connected to a VEX V5 3-Wire port. It provides access to the current analog value and allows callback functions to be registered for value changes.
Κατασκευαστές κλάσεων#
analog_in(
triport::port &port );
Καταστροφέας κλάσης#
Destroys the analog_in object and releases associated resources.
~analog_in();
Παράμετροι#
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The 3-Wire Port that the Analog Input is connected to, written as |
Παράδειγμα#
// Create the analog_in instance on 3-Wire Port A
analog_in AnalogInA = analog_in(Brain.ThreeWirePort.A);
Συναρτήσεις Μελών#
The analog_in class includes the following member functions:
value— Returns the value of the Analog Input device.changed— Registers a callback function for when the analog input value changes.
Before calling any analog_in member functions, an analog_in instance must be created, as shown below:
/* This constructor is required to use an
Analog Input device. Replace the values
as needed. */
// Create the analog_in instance on 3-Wire Port A
analog_in AnalogInA = analog_in(Brain.ThreeWirePort.A);
value#
Επιστρέφει την τρέχουσα τιμή της αναλογικής εισόδου.
Available Functionsint32_t value(
analogUnits units );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
The unit to represent the value:
|
Αυτή η συνάρτηση επιστρέφει την τρέχουσα τιμή της αναλογικής εισόδου.
Examples// Get the current value of the Analog Input
int32_t value = AnalogInA.value();
changed#
Καταγράφει μια συνάρτηση επανάκλησης που θα κληθεί όταν αλλάξει η τιμή της αναλογικής εισόδου.
Available Functionsvoid changed( void (* callback)(void) );
Παράμετρος |
Τύπος |
Περιγραφή |
|---|---|---|
|
|
Μια συνάρτηση που θα καλείται όταν αλλάζει η τιμή της αναλογικής εισόδου. |
Αυτή η συνάρτηση δεν επιστρέφει τιμή.
ExamplesDefine the callback function (outside of
int main())// Display a message when the input changes void AnalogInputChanged() { Brain.Screen.print("analog input changed"); }Register the callback inside
int main()int main() { /* vexcodeInit() is only required when using VEXcode. Remove vexcodeInit() if compiling in VS Code. */ vexcodeInit(); // Run AnalogInputChanged when the value of the // Analog Input changes AnalogInA.changed(AnalogInputChanged); }