Now that all ten triangle coordinates have been added to the 2D list, you will need to keep track of the order that the arm draws each of them. To do this, the Index variable will be created and its initial value will be set to ‘1’ for the starting location of triangle coordinate point 1, or row 1 of the 2D list.
Next, a [Repeat] block will be used. The [Repeat] block will repeat the same number of times as the number of rows in your 2D List. This will ensure that the arm will move to all ten points in the 2D List.
The Index variable can be changed after each iteration of the [Repeat] block to keep track of which triangle coordinates have already been drawn, and which one should be drawn next. To do this, a [Change variable] block will be used.
In VEXcode V5, follow the steps in this video to create the Index variable and add the [Set variable] block to the project.
Ensure you are using your mastering and triangle coordinate values, and not the ones displayed in this video.
Follow the steps in this video to add a [Repeat], (Length of 2D List), and [Linear move] block to the project.
- The [Repeat] block is used to move the arm to all ten points in the 2D list.
- The (Length of 2D List) block is used to tell the [Repeat] block to repeat ten times, the same the length of the 2D list.
- The [Linear move] block is used to tell the arm the (x, y, z) coordinates of the ten points in the 2D list.
Follow the steps in this video to add the Index variable and (Item of 2D list) block to the project.
- The first parameter of the (Item of 2D List) block for the x, y, and z-values is the Index variable.
- The second parameter of the (Item of 2D List) block for the x-value is set to ‘1’ to indicate the first column of the 2D List.
- The second parameter of the (Item of 2D List) block for the y-value is set to ‘2’ to indicate the second column of the 2D List.
- The second parameter of the (Item of 2D List) block for the z-value is set to ‘3’ to indicate the third column of the 2D List.
Follow the steps in this video to add a [Change variable] block to the project. The [Change variable] block is used to change the Index variable by one each time the [Repeat] block executes. This ensures that all ten coordinates in the 2D list are executed in the project.
Download and run the project. The arm will draw two triangles on the whiteboard.
If your arm did not draw two triangles on the whiteboard, notify your teacher.
Once you have finished coding the arm to draw two triangles on the whiteboard, stop the project and check in with your teacher.