We can use this function to read and store the value of individual barcode segments, my robot moves forward 72 degrees of wheel rotation. Because this is equal to the four centimeter distance between my tape segments, I set the speed to 30% to limit the effects of inertia. When the robot stops with its sensor over the line, it reads the color sensor value, like values give a sensor reading below the threshold of 160 and white above. The FL statement will now set the bool variable line marker to either true or false. However, using this, we can only read one line. We need to read and save five.
So how will we do that? First, we'll need to create the storage space. We'll change the line marker variable we created earlier to an array with five elements to store the five binary values. Then to record the five lines, we'll use a for loop with our function inside it to store the five binary numbers. Note that we use the same variable i for the index to the line marker array. As I increases by one each time the for loop iterates.
Every binary number will be stored in a different index. We'll have the five bit number saved in our line marker array. After this loop ends. The sleep 500 milliseconds command at the end gives the robot time to pause over each line.