Execute the Code
Before you can upload the sketch to the PULSE, remember to check your
connections. Upload the sketch. The green LED will light up, indicating the code
is ready to execute. When this has occurred, disconnect the USB cable and set the
Codee Bot on the floor.
Press the green Start button to execute the sketch. Observe the direction and
duration of the Codee Bot’s motion. Based on the sketch comments, did the
behavior match expectations?
Further Investigate
This sketch implements one new program structure in the form of the repeat-do
block. The repeat-do block allows for the statements within the block to repeat for a
specific number of times. This makes a simpler, easier-to-read sketch.
The repeat-do block is used to repeat a block of code contained within it. An
increment counter is used to count the number of times the code is executed
before the loop is terminated. The repeat-do block is useful for limiting the number
of times a loop will execute (Figure 54).
When you made the Codee Bot drive in a square in Activity 9, you listed each action
line by line, resulting in excessive code that looked more complicated than it was.
You start the loop with the repeat-do block to define how many times you want the
loop to repeat. The loop will repeat four times in the program. Within the loop, the
robot is programmed to drive forward and turn (Figure 55). This is named the called
function because it occurs outside the setup-loop block.
Figure 54
Figure 55
Tip: Depending on the
surface type, your bot might
not execute a perfect square.
Building and Coding the PULSE CodeeBot 101