Διακόπτης προφυλακτήρα#

Εισαγωγή#

The bumper class is used to detect when the Bumper Switch is pressed and released.

Κατασκευαστής κλάσης#

bumper( 
  int32_t index );

Καταστροφέας κλάσης#

Destroys the bumper object and releases associated resources.

virtual ~bumper();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

index

int32_t

The Smart Port that the Bumper Switch is connected to, written as PORTx, where x is the port number (for example, PORT1).

Παράδειγμα#

// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);

Συναρτήσεις Μελών#

The bumper class includes the following member functions:

  • pressing — Returns if the Bumper Switch is being pressed.

  • pressed — Registers a function to be called when the Bumper Switch is pressed.

  • released — Registers a function to be called when the Bumper Switch is released.

Before calling any bumper member functions, a bumper instance must be created, as shown below:

/* This constructor is required when using VS Code.
Bumper Switch configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a bumper instance in Port 1
bumper Bumper1 = bumper(PORT1);

pressing#

Επιστρέφει εάν ο διακόπτης προφυλακτήρα είναι πατημένος τη δεδομένη στιγμή.

Available Functions
int32_t pressing();

Parameters

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Return Values

Returns an int32_t indicating whether the Bumper Switch is being pressed.

  • 1 — The Bumper Switch is being pressed.

  • 0 — The Bumper Switch is not being pressed.

pressed#

Καταγράφει μια λειτουργία που θα κληθεί όταν πατηθεί ο διακόπτης προφυλακτήρα.

Available Functions
void pressed( void (* callback)(void) );

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

Ένας δείκτης σε μια συνάρτηση που θα κληθεί όταν πατηθεί το κουμπί bumper. Η συνάρτηση δεν πρέπει να δέχεται παραμέτρους και να επιστρέφει void.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Examples

Define the callback function (outside of int main())

// Display a message when bumper is pressed
void BumperPressed() {
  Brain.Screen.print("Bumper pressed");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run BumperPressed when the value of the Bumper Switch is pressed.
  Bumper1.pressed(BumperPressed);
}

released#

Καταγράφει μια συνάρτηση που θα κληθεί όταν απελευθερωθεί ο διακόπτης προφυλακτήρα.

Available Functions
void released( void (* callback)(void) );

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(void)

Ένας δείκτης σε μια συνάρτηση που θα κληθεί όταν απελευθερωθεί το bumper. Η συνάρτηση δεν πρέπει να δέχεται παραμέτρους και να επιστρέφει void.

Return Values

Αυτή η συνάρτηση δεν επιστρέφει τιμή.

Examples

Define the callback function (outside of int main())

// Display a message when bumper is released
void BumperReleased() {
  Brain.Screen.print("Bumper released");
}

Register the callback inside int main()

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  // Run BumperReleased when the value of the Bumper Switch is released.
  Bumper1.released(BumperReleased);
}