The My Block we just created to make a square is great, but what happens if you want a bigger square? Or if you want the robot to drive in a square faster? What if you want a triangle?
You could go into the My Block and change the inputs each time, but there is a better way.
Set up your mini-program, just as you did for the first My Block: Select the blocks you want, then Select “My Block Builder” in the Tools menu to start the My Block Builder.
Fill in all the sections just as you did for the first My Block, but don’t click Finish just yet. Instead, click the + symbol on the My Block to add a parameter.
In the Parameter Setup Tab, fill in the appropriate information. This will let us control how big our square will be.
Set the Default Value, for example, to 1000, just in case you forget to set it when using the My Block in your own programs. You can even select a slider bar style for your parameter.
In the Parameter Icons tab, select an appropriate image for the parameter. In this example we are controlling the distance the robot will drive when making a square, so a straight arrow seems appropriate.
Now that you have added your parameter, click Finish.
The new parameter, “Distance”, needs to be connected to the input in the mini-program before we can control it.
Connect the wire coming out of your parameter Distance into the Degrees input of the first Move Tank block. This lets us control how large of a square the robot will drive (see
Data Wires for more information).
Move back to your main program, and you will now see your My Block, but this time with a parameter to set the side length for the square mini-program. Depending on the Parameter Style selected above, you can either enter the value directly or use the slider bars.
What if you want your robot to drive in a triangle or hexagon?
Here’s the same My Block, but this time with parameters to control:
1. The distance to drive for each side (Distance),
2. How fast the robot goes (Speed),
3. What angle to turn for each corner, and
4. How many times to repeat the driving commands.
