Back
Main
Next
Day 7
Topics
Line following
Nested if/else and loops
Preparation
Handouts
Line Following Handout
Lesson
Since the students arn't learning any new icons or sensors, today is devoted to reiterating what they already know. One of the common problems students have is that they don't know when to use which structure. So today's lesson begins with a discussion of loops, if/else and wait-fors. When should they be used and what sort of English words indicate them. It is best to have the kids brainstorm the answers themselves. When finished you should have something like this:
1.Loops: repeat sections of code.
Keywords: while, every, repeat, x times
2.If/Else: decides between two choices.
Keywords: if, else, or
3.Wait-for: waits for something to happen.
Keywords: until, wait
Now that they understand when to use each structure lets look at a more complex program. Put this program up on the board:
Explain that some programs look very complex but when broken down into smaller programs, they are actually quite simple. For example this program. Begin by asking them what section one of the program does. The answer should be that it causes the robot to go forward as long as it is looking at white or green. (greater than 35) Next ask them about section 2. This section causes the robot to go backwards until it sees a green or black line. (less than 40) Now that they understand the two main components of the program ask what the whole program does. This program should cause the robot to go forward till it sees a black line (not a green one), it will then backup until it sees either a black or green line, loop back to the beginning and do it again. Use your pre-programed example robot to demenstrait this program to the class.
Next explain that using these techniques it is possible to build more complex, cool looking programs like the ones they will be doing today. Again using your pre-programmed robot, show them how it can follow the oval track.
Give them the handouts and make sure that no student starts challenges 3 & 4 without doing 1 & 2. 1 & 2 are simple programs but contain information necissary to complete 3 & 4.
Here is a more detailed explaination of challenges 3 & 4:
Challenge 3 Line following:
This program uses the circular (oval) track provided with the Lego Mindstorm kits. The student groups should create a program that will allow the robot to completely circle the track at least once. Note: this program can be completed using loops, if/else, wait-for, or any combenation.
Challenge 4 Cup Clearing
This program also uses the oval found in Lego Mindstorm kits. Five cups are placed randomly inside of the oval. The robot is also placed at a random point inside the oval. At no time can the robot compleatly leave the oval though it can be mostly out as long as it isn't all the way. The goal is the clear as many cups from the oval as possible in 1 minuet.
Back
Main
Next