Cerebro#
Introducción#
La categoría de detección cerebral del VEX IQ (2.ª generación) ofrece métodos para interactuar con los botones del dispositivo y la batería conectada.
This page uses brain as the example Brain name. Replace it with your own configured name as needed.
A continuación se muestra una lista de todos los métodos:
Acciones: Interactúa con los botones del VEX IQ (2.ª generación).
pressed— Registers a function to be called when the specified button is pressed.released— Registers a function to be called when the specified button is released.
Obtenedores: Devuelven datos de los botones y la batería.
pressing— Returns whether the specified button is being pressed.capacity— Returns the remaining battery capacity.voltage— Returns the voltage of the battery.current— Returns the current drawn by the battery.
Constructores: Inicialice manualmente el cerebro.
brain— Create a brain.
Comportamiento#
pressed#
pressed registers a function to be called when a specific button on the Brain is pressed. This method must be called on a specific button object, such as buttonCheck — (see full list of button objects below).
Uso:
Se puede usar uno de los tres objetos de botón disponibles con este método, como se muestra a continuación:
Botón |
Dominio |
|---|---|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando se presiona el botón especificado. |
|
Opcional. Una tupla que contiene los argumentos que se pasarán a la función de devolución de llamada. Consulte Funciones con parámetros para obtener más información. |
# Turn in a circle when the left button
# is pressed
def button_pressed():
drivetrain.turn_for(RIGHT, 360, DEGREES)
brain.buttonLeft.pressed(button_pressed)
released#
released registers a function to be called when a specific button on the Brain is released. This method must be called on a specific button object, such as buttonCheck — (see full list of button objects below).
Uso:
Se puede usar uno de los tres objetos de botón disponibles con este método, como se muestra a continuación:
Botón |
Dominio |
|---|---|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
|
Una función que se define previamente para ejecutarse cuando se suelta el botón especificado. |
|
Opcional. Una tupla que contiene los argumentos que se pasarán a la función de devolución de llamada. Consulte Funciones con parámetros para obtener más información. |
# Turn in a circle when the left button
# is released
def button_released():
drivetrain.turn_for(LEFT, 360, DEGREES)
brain.buttonLeft.released(button_released)
Captadores#
pressing#
pressing returns a Boolean indicating whether a specific button on the Brain is currently being pressed. This method must be called on a specific button object, such as buttonCheck (see full list of button objects below).
True— The specified button is being pressed.False— The specified button is not being pressed.
Uso:
Se puede usar uno de los tres objetos de botón disponibles con este método, como se muestra a continuación:
Botón |
Dominio |
|---|---|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Turn when the check button is pressed
while True:
if brain.buttonCheck.pressing():
drivetrain.turn(RIGHT)
else:
drivetrain.stop()
capacity#
capacity returns the remaining capacity of the battery as a percentage.
Usage:
brain.battery.capacity()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Display the current battery capacity
brain.screen.print(brain.battery.capacity())
voltage#
voltage returns the voltage of the battery as a float.
Usage:
brain.battery.voltage(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The unit that represents the voltage:
|
# Display the current voltage of the battery
brain.screen.print(brain.battery.voltage())
current#
current returns the current drawn from the battery in milliamps as a float.
Usage:
brain.battery.current()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Display the current of the battery
brain.screen.print(brain.battery.current())
Constructores#
Brain#
Brain creates an object of the brain class.
Usage:
brain = Brain()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
brain = Brain()
# Turn when the check button is pressed
while True:
if brain.buttonCheck.pressing():
drivetrain.turn(RIGHT)
else:
drivetrain.stop()