Project 11: Remembering Which Way to Score

Project 11: remembering which way to score.

We can remember the starting direction by assigning a variable to store the direction of the compass sensor at the start:

Then in an if statement we can check if our current direction is greater than, less than, or equal to the stored direction.

So at the start of the program, we can store the direction we are facing, and everytime we see the ball, we can see if we are facing right or left relative to our starting direction. (Keep in mind there is wrap around, so if we start at 40 deg, and are facing 340 deg, 340 > 40 but we would be facing left)

Make a program that makes the robot point towards the direction is originally faced at the start of the program.

Back to blog