Help with 3 Pi timers used for maze solving code


I’m working on improving the maze solving code(no loops) used for the 3 pi. I would like to get it to run as efficiently as the example in Ben’s youtube video.

He made a suggestion to use 2 parallel arrays to store both the action(turn) at each intersection and the time spent traveling to each segment. I was trying to read through the pololu AVR library command reference section 17 that gave info about the timers; but, I’m having trouble applying them to the maze solver code.

Specifically, i’m not really sure how to use the functions to record the length of each segment and to reset the timer to repeat the same function until the maze is solved. I’m not asking for anyone to write the code for me, maybe just explain how to use them with a very basic example.

I’m relatively new to programming and this is part of a school project. Any help other than “read the user guide” would be appreciated. Thank you.


You can use a global variable to keep track of the previous intersection time and subtract that from the running millisecond timer when you reach the next intersection:

intersectionLength = get_ms() - prevTimeMs;
prevTimeMs = get_ms();

Have you seen the command reference for the Pololu AVR library?

Note, however, that timing the path lengths and adjusting your speed based on those lengths should probably one of the later optimizations you make. There is plenty of room for improvement in our basic maze-solving example, including getting the overall speed higher and taking the turns faster.

- Ben