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

Εισαγωγή#

The bumper class is used with the Bumper Switch, a mechanical switch that completes a circuit when pressed, allowing the robot to detect presses and releases.

Ο διακόπτης προφυλακτήρα VEX V5 είναι μια συσκευή 3 καλωδίων με μια φαρδιά μαύρη βάση για να τη συνδέσετε σε ένα ρομπότ και ένα κόκκινο κουμπί που πιέζεται στην κορυφή.

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

bumper(
  triport::port &port );

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

Destroys the bumper object and releases associated resources.

virtual ~bumper();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

port

triport::port&

The 3-Wire Port that the Bumper Switch is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

Παράδειγμα#

// Create a bumper instance in Port A
bumper BumperA = bumper(Brain.ThreeWirePort.A);

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

The bumper class includes the following member functions:

  • pressing — Returns whether 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 A
bumper BumperA = bumper(Brain.ThreeWirePort.A);

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)

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

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.
  BumperA.pressed(BumperPressed);
}

released#

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

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

Parameters

Παράμετρος

Τύπος

Περιγραφή

callback

void (*)(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.
  BumperA.released(BumperReleased);
}