Control (Part 2)

-> 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

"IF-THEN" block

6-control-if-Then

If [something happens] Then [do something]

Any color (2)

Notice that robot make 2 type of desicions.

7-1-control-if-Else

If ["color sensor" reads green] Then [move FORWARD for 600 degrees at speed of 50%]

If ["color sensor" DON'T reads green] Then [move BACKWARD for 600 degrees at speed of 50%]

"IF-THEN x3" block

6-5-control-ifs

If [something happens]: robot detect something in its surrounding.

Then [do something]: the robot will decide what to do next.

Notice that robot make 4 type of desicions.

1- IF [no color] THEN [Not move (since there's no blocks outside the loop)]

2- IF[reads black] THEN[Move backward 500 degrees at the speed of 20].

3- IF[reads yellow] THEN[Make a pivot turn of 600 degrees at the speed of 20].

4- IF[reads white] THEN[Move forward 500 degrees at the speed of 20].

6-6-control-ifs

Notice that the order does not matter

Observation for If-then


"If-Else" block

6-control-if-Then

'If-Else' gives your robot a choice. If [Option A happens], do option A. Else, if [Option A not happen], Option B happens.

Any color (1)

'If something happens, do this. But if something else happens, do that instead!'

7-1-control-if-Else

If [read green] then [move FORWARD 600 degrees at speed of 50%].

Else [if NO green] then [ove BACKWARD 600 degrees at speed of 50%].


"Stop and Exit" block

8-control-exit

STOP means telling your robot to take a break and EXIT means it's time for your robot to say goodbye to the program.

Sensor (10)

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

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

3- Robot stops moving.

4- Exit the program. The robot no longer listen to the code.

7-1-control-if-Else

Notice that you don't have to press the "Stop" button on the screen. The robot turn off by itself.

Key-Takeaways: why are loops important for programming?

Time for a quiz!

Question goes here

Challenge for you

IMG 1391

Hint:

-> The speed of moving backward is 30%

Use: Ultrasonic Sensor (in the sensor).

untrasonic-hint

-> Add a "Stop and Exit" block

You-control

Notice that you need to add a spin turn in between the loops

You can either use [Repeat Until] OR [Wait Until]

Don's worry, we will learn the SENSORS next!