In the previous lesson we learned how to use the Linkbot to trace a square. To do so, we used the code blocks shown below. Note that we used the same driveDistance and turn commands four times in a row. That is, we instructed the Linkbot to drive 12 units, then turn left 90 degrees, then drive 12 units, then turn left 90 degrees, and so on for the third and fourth sides. For a basic loop, we put the commands we want to have repeated inside a special loop code block, and then specify how many times we want the commands to be repeated. This is known as a "repeat loop," and it's available in the RoboBlockly "Loops" menu of code blocks. (As you continue to learn about programming, you will come across other types of loops as well.) In this lesson you will get to experiment with a repeat loop to have the RAV robot traverse the square.
|
Grid Size: S M L | Simple View: | MinView: |
Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
72x72 inches | 96x96 inches | 192x192 inches | ||
1x1 inches | 2x2 inches | Fraction: | ||
xy-Range: | ||||
|
||||
|
||||
Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
Units: | US Customary | Metric | Ruler: |
Labels: |
|
|
|
Font
px
|
|
Tics Lines: |
|
Width
px
|
Hash Lines: |
|
Width
px
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
|
The pre-placed code blocks use a loop to draw two sides of a square. Use the Step button to step through the code piece by piece to see how it works. Then change the value of the argument in the loop so that the code has the robot draw a complete square with four sides. What happens if you have the loop repeat more than four times? |
|
|
|||||||||||
|
|||||||||||