08 Mission Instructions

Your mission is to design a robot that can be the Traffic Light for a game of Red Light, Green Light. Then you can play alone or with your friends.  To be successful, your robot will need to:

      1. Randomly change between two different colored LEDs
      2. Sense motion during a "Red Light"
      3. Declare when the robot wins or loses

9. Fun and Fair Games are Best

If your motion sensor is anything like mine, that was a very disappointing game to play. I lost every single time!

If you had trouble winning your game, this step might be exactly the solution that you need.  We want the motion sensor to be a little less sensitive. 

Instead of detecting every slightest hint of movement, let’s ask it to count how many tiny movements it detects and if it counts high enough, THEN we’ll lose the game. 

To do this, we’ll create a finite state machine like you did in Mission 07.  Let’s name the new variable motion_count. Set motion_count to 0 at the very top of your program. Right next to the motion_detected variable. 


Then we’ll modify the motion_detected conditional statement. Instead of just detecting the slightest movement and immediately ending the game, when the robot detects a movement, it will count up by 1 (change by 1).

IF motion_count ever gets above 8, THEN it is fair to end the game and we’ll admit defeat. But IF motion is not detected, then we’ll get a pass and reset the count back to zero!

NOTE: Change your motion_count > [ # ] to make the game easier or harder to win. We experimented for a while in our labs. Some people enjoyed their game with a number as low as 3, others liked the game with numbers as high as 11! It all depends on how still you can be during a Red Light! 

Finally, let’s really make sure this game is fair and we really stand a chance at winning, let’s also reset the motion_count back to zero even if the robot notices we won.  It never hurts to be a little extra!