Step 7

Finishing the code


Now we just have a little bit of code left to complete our function and the whole program!

The code to detect a wall is pretty simple. All we need to do is check if both our bumpers are being pressed, if they are, we hit a wall! We then tell our robot to stop driving, and set the “Wall” variable to true, ending the loop.

To detect if we have completed the maze, we use the checkerboard pattern at the end. We use our DownEye sensor to tell us if it detects red, if it does, we set the “allDone” variable to true, ending the loop.

Once you have finished all this code, go ahead and test it out. If coded correctly, your robot should be able to make it out of any maze! If not, double check your code for any mistakes.

Once it’s working, see if there are any ways you could further improve this plan/algorithm. Are there any other solutions/algorithms you can think of to solve this problem? Try coding them to see if they work! There are definitely better ways to solve this problem, this was just one of the easier solutions.