Code to Note
Let’s take a look at the code and what to expect.
Click on image for a closer view
black_Line_L and black_Line_R
Like in the previous experiment, you need to set a baseline value for the surface that your robot is driving on. This
is actually called a calibration value. We need to do this for two sensors now; left and right. We go through the
same routine we did for the single sensor previously, but for the left and right sensors.
Comma Delimiter
For debugging, we set up the serial again. However, we will use the
join
block with a comma delimiter. This is
useful for graphing more than one sensor readings.
On Button Press
As in the first experiment, we use the
On Button Press
block to start the program. Since we are using button A
again to recalibrate the line following sensors whenever we need, we'll be using button B to start the program. This
is so you can get a good base reading to calibrate your sensors without having to wrestle with a robot that is trying
to move around. To remind us to press button B, the
on start
block displays a short animation once to point at
button B. If the motor switch is flipped to the RUN MOTORS side, pressing button B will cause the micro:bot to
start following a line.
While
The
block is a logic block that is similar to the
loop
block, but a bit smarter. The
While
block accepts a
TRUE/FALSE statement, if that statement is true the block will loop whatever code is placed inside of it. If that
value is false, the
While
block is simply skipped over. We hardcode a
true
value into the
While
block so that it
analog read pin
P0
analog read pin
P2
set
black Line R
to
set
black_Line_L
to