As drivers, we need to follow certain rules of the road. The most common rule of all is to stop at stop signs, so that is what we are going to be doing! We want our Zumi to drive forward until she sees a stop sign. Once she sees a stop sign, we want her to stop and then take a left turn! Let’s see how we can do that.
Lesson 4 introduced us to the idea of a loop – when a certain section code repeats over and over again. However, unlike Lesson 4, now we don’t know how much time Zumi should go forward for. Still, we do know that we want Zumi to drive forward until she sees a stop sign. Go to the loops tab and grab the “repeat while” block.
Click on the dropdown menu and select “until”. This is because we want Zumi to drive forward until she sees a stop sign.
Combining our new knowledge of the until loop with the camera code, we can ensure that Zumi will only go forward until she sees a stop sign. Include a wait block so that Zumi can be still as she takes her picture. If she does not see a stop sign, she moves forward for 1 second at 40 speed (you can change this if you want!) and takes another picture to see if she sees a stop sign now.
Great! Zumi now stops at stop signs! Now, let’s get Zumi to turn left afterwards. Where should we put this block? Let’s think about it chronologically (in order by time).
- Zumi starts driving forward.
- Zumi eventually sees a stop sign.
- After Zumi sees a stop sign, she stops going forward, and she takes a left.
After listing everything out in order, it appears that we can put the left turn after Zumi sees a stop sign. Even better, once Zumi sees a stop sign, she exits the loop. That means we can put the left turn right after the loop. It is often helpful to think of code chronologically when deciding where to put what!
Zumi can now stop at stop signs and make a turn. She’s really starting to feel like she can drive herself!