Figure 59
The second part of the if-do block executes the while() loop block. A while()
loop looks at a test condition in the block and will loop continually until the test
condition set in the block becomes false. In this program, it will repeat what’s in
the while() loop as long as the Line Finder Sensor reads a value of 1 (Figure 59). The
program will continue blinking the red LED until the sketch is reset.
Extension Activity
With the example as a reference, try creating a new sketch to have the Codee Bot
drive to a black line and stop. Remember what you have learned from your previous
activities. Challenge yourself to create different behaviors for when the Codee Bot
meets a line, such as backing up or turning a different direction.
Real-World Link
With the advent of self-driving cars, cars need to be able to sense lines in the road. If
the car pulls up to an intersection, it needs to stop at the line. It can do this using a
sensor that detects the line.
Careers: automotive software engineer, electrical engineer, digital sculptor
STEM Connections
• Science
Ĕ Velocity
Ĕ Acceleration
• Technology
Ĕ Sensors
Ĕ while() loops
• Engineering
Ĕ Problem solving
Ĕ Line following
• Math
Ĕ Logic statements
Ĕ Speed calculations
106 Building and Coding the PULSE CodeeBot