Events#
When Started#
The When Started block is used to run the attached stack of blocks when the project is started.
when started :: hat events
A when started event will run when the project is started from the start button in VEXcode Blocks.
All new projects will automatically include a when started block.
In this example, the 6-Axis Arm will move to the coordinates (120, 120, 75) in millimeters.
when started :: hat events
move [arm v] to position x: (120) y: (120) z: (75) [mm v] ▶
When Timer#
The When Timer block is used to run the attached stack of blocks when the Brain’s timer is equal to the given value.
when timer > (1) seconds :: hat events
The Brain’s timer begins at the beginning of each project or whenever the Brain’s timer is reset.
Choose an amount of time. The when timer event will run once the Brain’s timer is equal to the entered amount.
when timer > (3.25) seconds :: hat events
In this example, after 5 seconds have passed, the Robot will print the message to the Print Console.
when timer > (5) seconds :: hat events
print [5 seconds have passed .] ▶
When I Receive#
The When I Receive block is used to run the attached stack of blocks when the selected message is received from a broadcasted message.
when I receive [message1 v]
Choose which message to listen for. A new message can also be created.
In this example, the code will continuously check if the 6-Axis Arm can move +20 mm on the x axis. If the 6-Axis Arm can move for that distance, a message will be broadcasted to move that distance.
when started :: hat events
forever
[Continuously check if the Arm can move +20 mm on the x axis.]
if <[arm v] increment position by x: (20) y: (0) z: (0) [mm v] ?> then
[Every time the 6-Axis can move, broadcast the message.]
broadcast [arm_can_move v]
when I receive [arm_can_move v]
[When the message is received, move the Arm +20 mm on the x axis.]
increment [arm v] position by x: (20) y: (0) z: (0) [mm v] ▶
Broadcast#
The Broadcast block is used to broadcast a message to activate any stacks that begin with a When I Receive block listening for the broadcasted message.
broadcast (message1 v)
The stack that sends the broadcast will continue to run blocks at the same time as other stacks that receive the broadcasted message.
Choose which message to broadcast. A new message can also be created.
In this example, the code will continuously check if the 6-Axis Arm can move +20 mm on the x axis. If the 6-Axis Arm can move for that distance, a message will be broadcasted to move that distance.
when started :: hat events
forever
[Continuously check if the Arm can move +20 mm on the x axis.]
if <[arm v] increment position by x: (20) y: (0) z: (0) [mm v] ?> then
[Every time the 6-Axis Arm can move, broadcast the message.]
broadcast [arm_can_move v]
when I receive [arm_can_move v]
[When the message is received, move the Arm +20 mm on the x axis.]
increment [arm v] position by x: (20) y: (0) z: (0) [mm v] ▶
Broadcast and Wait#
The Broadcast and Wait block is used to broadcast a message to activate any stacks that begin with a When I Receive block listening for the broadcasted message while also pausing the rest of the stack.
This block broadcasts a message to activate any stacks that begin with a when I receive block listening for the broadcasted message while also pausing the rest of the stack.
broadcast (message1 v) and wait
The stack that sends the broadcast and wait will pause until the other stacks that receive the broadcasted message have completed.
Choose which message to broadcast. A new message can also be created.
In this example, the code will continuously check if the 6-Axis Arm can move +20 mm on the x axis. If the 6-Axis Arm can move for that distance, a message will be broadcasted to move that distance.
when started :: hat events
forever
[Continously check if the Arm can move +20 mm on the x axis.]
if <[arm v] increment position by x: (20) y: (0) z: (0) [mm v] ?> then
[Every time the 6-Axis Arm can move, broadcast the message.]
broadcast [arm_can_move v] and wait
when I receive [arm_can_move v]
[When the message is received, move the Arm +20 mm on the x axis.]
increment [arm v] position by x: (20) y: (0) z: (0) [mm v] ▶