Control (Part 1)

-> Control blocks are what tell your robot what to do and when to do it by using "Loops"

-> A loop is like a magic spell that says, "Do this action again and again until I say stop!"

"Wait" block

1-control-wait

"Wait Until" block

2-control-waitUntil

"Repeat" block

3-control-repeat

"Forever" block

4-control-forever

"Repeat Until" block

5-control-repeat-Until

"If-Then" block

6-control-if-Then

"If-Else" block

7-control-If-Else

"Stop and Exit program" block

8-control-exit

Build the entire robot by:

If you have not done so

IMG-2019 IMG-2018

"Wait" Block

1-control-wait

This block it's to make the robot do nothing but wait for [how many seconds you want].

a waitss BABY ROBOT

1- Robot go forward for 450 degrees at the speed of 50%.

2- Then, robot stop and do nothing for 1 second. It waits.

3- Motor A goes up for 250 degrees at the speed of 75%.

Screenshot-2024-05-14-at-07-28-14

Observation: Notice that the robot takes a pause of 1 second.


"Wait Until" Block

2-control-waitUntil

Telling your robot to stop and wait patiently until a certain condition is met.

RED START

1- Robot [starts moving] backward at the speed of 50%.

2- It moves forever UNTIL the "color sensor" find red.

3- Robot stops moving.

2-3-control-wait-Until

Remember that -50% for both, it's the same as saying going backward at speed of 50%

[Start moving] vs [Move]

2-2-control-movement-start

VS

Control-MOvement-move

Take a look at the difference between these 2 type of movements blocks:

[Start moving]

RED START 2-3-control-wait-Until

Notice that without a set amount of degrees, the robot only moves backward, forever, unless there's a condition.

[Move]

RED NO 2-4-control-wait-Until

Notice that the robot doesn't listen to the code, it only moves backwards for 600 degrees.

Observation


"Repeat"

3-control-repeat

Doing It Again and Again. Make the robot do something the amount of times you want the robot to do.

Without "Repeat"

Movem pink (1) Screenshot-2024-05-13-at-12-18-47

Remember this code from Movement challenge?

It makes the robot move in a square for 4 times

With "Repeat"

Movem pink (2) Screenshot-2024-05-14-at-07-29-47

Now look at this one.

It looks much more simple, and easier to read.

1- Robot moves forward for 500 degrees at speed of 50%.

2- Make a pivot turn of 590 degrees at speed of 40%.

3- Wait for 0.5 seconds

Repeat this 4 times


"Forever" block

4-control-forever

Forever: make something to repeat limitless times. NO stopping

FOREVER

The light of the robot's navigation buttons change color from orange and green FOREVER.

4-1-control-forever

Notice that the button of the "forever" block is a line. You can't add more blocks under "forever" block.


"REPEAT UNTIL" block

5-control-repeat-Until

Is a loop that: [keeps doing something] UNTIL [a certain condition is met]

BLUE

1- Robot moves forward, without knowing how much.

2- It moves forward UNTIL the "color sensor" read color BLUE

3- The robot stops moving.

5-1-control-repeat-Until

You need to add a [stop moving] under the loop.

If not, the robot will move forever, without stopping.

Key-Takeaways: why are loops important for programming?