In the previous lesson we learned about repeat loops and used pre-placed loop code to have the Linkbot trace out a square by drawing one side of the square each time around the loop. In this lesson we'll create our own loop to draw a square, using the repeat loop code block: You can find this code block by clicking on the "Loops" button in the code blocks section (though we've already pre-placed it in the Workspace for you in this case). We'll also add a turn command at the beginning so that we can draw squares oriented at different angles. And we'll introduce a new command, blinkLED : It instructs the robot to blink its LED light for a specified number of seconds and a specified number of blinks.
|
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
|
|
|
Drag a driveDistance code block from the code block section to the Workspace and position it just inside the repeat loop code block, until it clicks into place. Then do the same for a turn code block and a blinkLED code block, so that you end up with the driveDistance , turn , and blinkLED code blocks all inside the repeat loop. Adjust the argument values for each code block, including the loop, so that when you run the code the robot traces out a square, blinking 3 times at each corner. Then try changing the angle value to 30 degrees (instead of 0 degrees) for the turn code block at the beginning of the code before the repeat loop, and run the code again. You should get a square tilted at that 30 degree angle. Try other angles, blinks, square sizes, and trace colors by changing the various argument values. Can you add another repeat loop after the first one to draw a second square of different size? Have fun! |
|
|
|||||||||||
|
|||||||||||