Events#
When Started#
The When Started block is used to run the attached stack of blocks when the project is started.
A when started event will run when the project is started from the start button in VEXcode.
All new projects will automatically include a when started block.
In this example, the When Started block is used to start the project. When the start button is selected, the robot will drive forward, turn right, and drive forward again.
When Bumper#
The When Bumper block is used to run the attached stack of blocks when the selected Bumper Switch sensor is pressed or released.
Choose which Bumper to use.
Select which action will trigger the event - pressed or released.
In this example, when the Bumper Switch sensor is pressed, a message will be printed on the Brain.
When Touch LED#
The When Touch LED block is used to run the selected VEX IQ Touch LED is pressed or released.
Choose which Touch LED to use.
Select which action will trigger the event - pressed or released.
In this example, when the Touch LED is pressed, a message will be printed on the Brain.
When Controller Axis#
The When Controller Axis block is used to run the attached stack of blocks when the selected IQ (2nd gen) Controller joystick axis is moved.
Choose which IQ (2nd gen) Controller joystick axis to use.
In this example, moving the D joystick axis on the IQ (2nd gen) Controller will print a message.
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.
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.
In this example, after 5 seconds have passed, the robot will print the message to the Print Console.
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.
Choose which message to listen for. A new message can also be created.
In this example, the code will continuously check if the Left Sensor Bumper was pressed. Once pressed, the When I Recieve block will trigger once the bumper_press
message is received.
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.
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 Left Sensor Bumper was pressed. Once pressed, the Broadcast block will trigger the When I Receive block with the message bumper_press
.
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.
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 Left Sensor Bumper was pressed. Once pressed, the Broadcast and Wait block will trigger the When I Receive block with the message bumper_press
. No code underneath the When Started block will execute until everything underneath the bumper_press
When I Receive block is finished.
When Optical Sensor#
The When Optical Sensor block is used to run the attached stack of blocks when the selected Optical Sensor detects or loses an object.
Choose an Optical Sensor.
Choose whether the When Optical detects/loses event is triggered when the sensor detects an object, or loses an object.
In this example, once the Optical Sensor has detected an object, a message will be printed to the Brain.
When Optical Sensor Detects a Gesture#
The When Optical Sensor Detects a Gesture block is used to run the attached stack of blocks when the selected Optical Sensor detects a gesture.
Important: The When Optical Sensor Detects a Gesture will not work unless the Optical Set Mode block is used to set the Optical Sensor to detect gestures.
Choose an Optical Sensor.
Choose which gesture will trigger the event block.
In this example, once the Optical Sensor has detected a left gesture, a message will be printed to the Brain.