活动#

保险杠.按下()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

打回来

先前定义的函数的名称。

**返回:**无。

# 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)

保险杠.释放()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

打回来

先前定义的函数的名称。

**返回:**无。

# 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)

大脑.计时器.事件()#

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.

这是一个非等待命令,允许任何后续命令无延迟地执行。

大脑的计时器在每个项目开始时或每次重置大脑的计时器时启动。

参数

描述

打回来

任何先前定义的函数。

时间

项目启动后等待的时间(以毫秒为单位)。

**返回:**无。

# 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)

我的事件 = 事件()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

我的事件

新事件的名称。不能包含任何数字。

**返回:**无。

# 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()

事件()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

事件

先前创建的事件的名称。

打回来

先前定义的函数的名称。

**返回:**无。

# 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()

事件.广播()#

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

这是一个非等待命令,任何后续命令都将执行,而无需等待任何监听器函数完成。

参数

描述

事件

先前创建的事件的名称。

**返回:**无。

# 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()

事件.broadcast_and_wait()#

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.

这是一个等待命令,将阻止任何后续命令执行,直到所有侦听器功能完成。

参数

描述

事件

先前创建的事件的名称。

**返回:**无。

# 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()

眼睛传感器.object_detected()#

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

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

眼部传感器

Which Eye Sensor to use: front_eye or down_eye.

打回来

先前定义的函数。

**返回:**无。

# 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)

眼睛传感器.object_lost()#

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.

这是一个非等待命令,允许任何后续命令无延迟地执行。

参数

描述

眼部传感器

Which Eye Sensor to use: front_eye or down_eye.

打回来

先前定义的函数。

**返回:**无。

# 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)