Using My Blocks in VEXcode IQ

 My Blocks is one of the block categories within VEXcode IQ. Some other categories include Looks, Sound, Sensing, and Variables. My Blocks are used to create a sequence of blocks that can be used multiple times throughout a project. 


 How to Make a Block

VEXcode IQ blocks Toolbox with the My Blocks category shown and the Make a Block button highlighted.

Select “Make a Block” from the My Blocks category.

VEXcode IQ Make a Block menu has been opened. The name of the block has been changed to Play sound and it is highlighted.

Rename the block by entering in the “block name” field, then select “OK.”


How to Customize a Block

Add an input (number)

VEXcode IQ Make a Block menu is open and the name of the block is set to Play sound. A number input field has been added to the block and is now highlighted.

Select the, “Add an Input (number)” option from the “Make a Block (Preview)” screen. Rename the input by entering in the “number” field, then select “OK.”

Add an input (boolean)

VEXcode IQ Make a Block menu is open and the name of the block is set to Play sound. A boolean input field has been added to the block and is now highlighted.

Select the, “Add an Input (Boolean)” option from the “Make a Block (Preview)” screen. Rename the input by entering in the “Boolean” field, then select “OK.”

Add a label

VEXcode IQ Make a Block menu is open and the name of the block is set to Draw a followed by a number input. A label field has been added to the end of the block and is now highlighted.

Select the, “Add a label” option from the “Make a Block (Preview)” screen. Rename the label by entering in the “label text” field, then select “OK.”

Combine inputs and labels

VEXcode IQ Make a Block menu is open and a custom block has been created. The block first reads Draw a, then has a number input field, and then ends with a label reading inch square. All together the custom block reads Draw a X inch square.

Combine inputs and labels together in order to create a sequence of blocks.


How to Delete Inputs / Labels

VEXcode IQ Make a Block menu is open and the name of the block is set to Play sound. A number input field has been added to the block, and the Clear icon above the input field is highlighted.

To delete an input or label, select the “clear” icon on top of the input or label that you wish to remove.


How to Use the Define Block

VEXcode IQ My Blocks Definition block is highlighted in the Workspace. The defined block reads 'Draw a size inch square', and the word size is a number parameter that can be used in the block definition.

A parameter can now be used from the “define” block once it is created.

The VEXcode IQ My Blocks Definition block with a code definition now added to it. The stack has a Repeat block set to 4, and a Drive for 200 mm block with a Turn for 90 degrees block both inside the Repeat block.

Attach additional blocks to the “define” block.

The VEXcode IQ My Blocks Definition block with the number parameter now used in the definition. The stack has a Repeat block set to 4, and a Drive for block above a Turn for 90 degrees block inside the repeat block. The number parameter has been placed into the Drive for block, so the block now reads Drive forward for size inches.

Use parameters from the “define” block.

VEXcode IQ My Blocks command block added below a When Started block to run the new block. This command block will call the Draw a size inch square command. The number parameter is set to 4.

Use the “My Block” attached to the “When Started” block.


How to Use My Blocks

Play Siren Example

In this example, the robot will use My Blocks to:

  • Play the siren sound 3 times
  • Drive forward for 12 inches
  • Play the siren sound 6 times

The “define” hat block breaks down a procedure. In the following example video, this “define” hat block breaks down the blocks used to play a siren sound a certain number of times. Drag arguments from the define block to be used within the blocks.

Once the “define” block is set, the newly created block can now be dragged and added to the “when started” block to set parameters. This process is shown in this video.

Play Siren Sound VEXcode IQ My Blocks Definition block. The block reads Play siren sound times, and the word times is a number parameter. The stack has a Repeat block with its repeat number set to the times parameter, and in the Repeat block there is a Play sound block set to play the siren sound. Next to the Definition block there is a stack with a program to use the block. This stack reads When started, play siren sound 3, drive forward for 12 inches, and then play siren sound 6.

Once the parameters are changed, the project is ready to be downloaded and run.

Print with New Line Example

In this example, the robot will use My Blocks to:

  • Drive forward for 15 inches
  • Print the battery capacity and also move the cursor to a new line on the Brain’s screen
  • Turn the robot 180 degrees to the right
  • Print the battery capacity and also move the cursor to a new line on the Brain’s screen

 

The “define” hat block breaks down the blocks used to print sensor reporter values and then move to a new line. Drag arguments from the define block to be used within the blocks, as shown in this video.

Once the “define” block is set, the newly created block can now be dragged and added to the “when started” block to set parameters. This process is shown in this video.

Print with New Line VEXcode IQ My Blocks Definition block. The block reads Print number with new line, and the word number is a number parameter. The stack has a Print block with the number parameter in its print value followed by a Next row block. Next to the Definition block there is a stack with a program to use the block. This stack reads When started, drive forward for 15 inches, print battery capacity in % with new line, turn right for 180 degrees, and then print battery capacity in % with new line.

Once the parameters are changed, the project is ready to be downloaded and run.

For more information, help, and tips, check out the many resources at VEX Professional Development Plus

Last Updated: