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

Εισαγωγή#

Ο Διακόπτης προφυλακτήρα είναι ένας μηχανικός διακόπτης που ολοκληρώνει ένα κύκλωμα όταν πατηθεί, επιτρέποντας στο ρομπότ να ανιχνεύει πατήματα και απελευθερώσεις.

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

This page uses bumper_switch as the example Bumper Switch name. Replace it with your own configured name as needed.

Παρακάτω είναι μια λίστα με τις διαθέσιμες μεθόδους:

  • pressing – Returns whether the Bumper Switch is being pressed.

  • pressed – Registers a function to be called whenever the Bumper Switch is pressed.

  • released – Registers a function to be called whenever the Bumper Switch is released.

Constructor – Μη αυτόματη αρχικοποίηση και ρύθμιση παραμέτρων ενός διακόπτη προφυλακτήρα.

  • Bumper – Create a Bumper Switch.

πιεστικός#

pressing returns a Boolean indicating whether the Bumper Switch is currently being pressed. This can be used to check if the robot bumps into other objects.

  • True – The Bumper Switch is being pressed.

  • False – The Bumper Switch is not being pressed.

Usage:
bumper_switch.pressing()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display a message after bumper_switch is pressed
while not bumper_switch.pressing():
  pass

brain.screen.print("Bumper Switch pressed!")

πιεσμένο#

pressed registers a function to be called whenever the Bumper Switch is pressed.

Usage:
bumper_switch.pressed(callback, arg)

Παράμετροι

Περιγραφή

callback

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

arg

Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information.

def my_function():
  brain.screen.print("Pressed")

# Call my_function whenever bumper_switch is pressed
bumper_switch.pressed(my_function)

κυκλοφόρησε#

released registers a function to be called whenever the Bumper Switch is released.

Usage:
bumper_switch.released(callback, arg)

Παράμετροι

Περιγραφή

callback

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

arg

Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information.

def my_function():
  brain.screen.print("Released")

# Call my_function whenever bumper_switch is released
bumper_switch.released(my_function)

Κατασκευαστής#

Constructors are used to manually create Bumper objects, which are necessary for configuring a Bumper Switch outside of VEXcode.

Bumper#

Bumper creates a Bumper Switch.

Usage:
Bumper(port)

Παράμετρος

Περιγραφή

port

The 3-Wire Port that the Bumper Switch is connected to:

  • On the EXP Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Bumper Switch in Port A
bumper_switch = Bumper(brain.three_wire_port.a)