The line follower sensor is usually used to follow a line, but in this lesson we are going to learn how it can be used to count lines instead. For this we are going to need a variable to count with. What other things do we need in the program? Write down some pseudocode before moving on.
Declare a variable.
---- If we see a line
---- ---- Add one to the variable.
At the end of this program, the number of lines that the mBot passed over should be held in the variable. We can write this in mBlock code. I decided to move forward and count lines for 10 seconds:
There are 2 problems with this code at the moment. The first one is that there is no way to read the count variable. Read the challenges and see if you can identify and solve the second problem.
Construct Your Dreams!