Eventos#

parachoques.presionado()#

The bumper.pressed(callback) command is used to run a specified function when the bumper is pressed.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

llamar de vuelta

El nombre de una función definida previamente.

Devoluciones: Ninguna.

# Define a new function called "bumper_was_pressed"
def bumper_was_pressed():
    brain.print("Bumper pressed!")
 
# Use the defined function in the callback parameter.
right_bumper.pressed(bumper_was_pressed)

parachoques.liberado()#

The bumper.released(callback) command is used to run a specified function when the bumper is released.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

llamar de vuelta

El nombre de una función definida previamente.

Devoluciones: Ninguna.

# Define a new function called "bumper_was_released"
def bumper_was_released():
    brain.print("Bumper released!")
 
# Use the defined function in the callback parameter.
right_bumper.released(bumper_was_released)

temporizador cerebral.evento()#

The brain.timer.event(callback, time) command is used to run the specified callback function when the Brain’s timer is equal to the specified time value.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

El temporizador del Cerebro comienza al comienzo de cada proyecto o cuando se reinicia el temporizador del Cerebro.

Parámetros

Descripción

llamar de vuelta

Cualquier función previamente definida.

tiempo

La cantidad de tiempo a esperar después del inicio del proyecto, en milisegundos.

Devoluciones: Ninguna.

# Define a new function called "five_second_event".
def five_second_event():
    brain.print("Five seconds have passed.")
  
# Create a timer to trigger the defined "five_second_event" after
# 5000 Milliseconds (5 seconds).
brain.timer_event(five_second_event, 5000)

mi_evento = Evento()#

The my_event = Event() command is used to create a new event.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

mi_evento

Un nombre para el nuevo evento. No puede contener números.

Devoluciones: Ninguna.

# Define a new function
def draw_line():
    pen.move(DOWN)
    drivetrain.drive_for(FORWARD, 400, MM)

def main():
    # Create a new draw event.
    draw_event = Event()

    # Register the defined function to the new event.
    draw_event(draw_line)

    # Wait 15 Milliseconds to give the event time to register.
    wait(15, MSEC)

    # Broadcast the draw event to trigger the defined function.
    draw_event.broadcast()

evento()#

The event(callback) command is used to register a callback function to run when an event is triggered.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

evento

El nombre de un evento creado previamente.

llamar de vuelta

El nombre de una función definida previamente.

Devoluciones: Ninguna.

# Define a new function
def draw_line():
    pen.move(DOWN)
    drivetrain.drive_for(FORWARD, 400, MM)

def main():
    # Create a new draw event.
    drawEvent = Event()

    # Register the defined function to the new event.
    drawEvent(draw_line)

    # Wait 15 Milliseconds to give the event time to register.
    wait(15, MSEC)

    # Broadcast the draw event to trigger the defined function.
    drawEvent.broadcast()

evento.transmisión()#

The event.broadcast() command is used to broadcast event messages to run listener functions.

Este es un comando sin espera y cualquier comando posterior se ejecutará sin esperar a que finalice ninguna función de escucha.

Parámetros

Descripción

evento

El nombre de un evento creado previamente.

Devoluciones: Ninguna.

# Define a new function
def draw_line():
    pen.move(DOWN)
    drivetrain.drive_for(FORWARD, 400, MM)

def main():
    # Create a new draw event.
    drawEvent = Event()

    # Register the defined function to the new event.
    drawEvent(draw_line)

    # Wait 15 Milliseconds to give the event time to register.
    wait(15, MSEC)

    # Broadcast the draw event to trigger the defined function.
    drawEvent.broadcast()

evento.transmisión_y_espera()#

The event.broadcast_and_wait() command is used to broadcast event message to run listener functions and wait for all listeners to finish before continuing.

Este es un comando en espera y evitará que se ejecuten comandos posteriores hasta que todas las funciones de escucha hayan finalizado.

Parámetros

Descripción

evento

El nombre de un evento creado previamente.

Devoluciones: Ninguna.

# Define a new function
def draw_line():
    pen.move(DOWN)
    drivetrain.drive_for(FORWARD, 400, MM)

def main():
    # Create a new draw event.
    drawEvent = Event()

    # Register the defined function to the new event.
    drawEvent(draw_line)

    # Wait 15 Milliseconds to give the event time to register.
    wait(15, MSEC)

    # Broadcast the draw event to trigger the defined function and wait for
    # the listener functions to finish before executing any subsequent
    # functions.
    drawEvent.broadcast_and_wait()

sensor_ocular.objeto_detectado()#

The eye_sensor.object_detected(callback) command is used to run the callback function when an object is detected by the Eye Sensor.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

sensor ocular

Which Eye Sensor to use: front_eye or down_eye.

llamar de vuelta

Una función previamente definida.

Devoluciones: Ninguna.

# Define a new function called "front_object_detected"
def front_object_detected():
    brain.print("Front eye detected an object!")

# Use the defined function in the callback parameter.
front_eye.object_detected(front_object_detected)

sensor_ocular.objeto_perdido()#

The eye_sensor.object_lost(callback) command can be used to run the callback function when an object is no longer being detected by the Eye Sensor.

Este es un comando sin espera y permite que cualquier comando posterior se ejecute sin demora.

Parámetros

Descripción

sensor ocular

Which Eye Sensor to use: front_eye or down_eye.

llamar de vuelta

Una función previamente definida.

Devoluciones: Ninguna.

# Define a new function called "front_object_detected"
def down_object_loss():
    brain.print("Down eye lost an object!")

# Use the defined function in the callback parameter.
down_eye.object_lost(down_object_loss)