Activity: Wind-up Rover

Create a classic wind up toy out of our rover. The rover records the number of seconds that it is held upside down and once placed right way up on a surface it will move forward. The longer the rover was held upside down the longer it will move forward and the faster it will go. For more interesting wind up rovers, incorporate the LEDs and Buzzers to also respond and change to the wind up time.

Relevant Coding Skills

Iteration
Variables
Maths

Relevant Rover Concepts

Accelerometer
Motors

Activity Demonstration

Setup

The only requirement for this exercise is there be a long enough space for the rover to move in. If you've got limited space you can add a limit to wind up time.

 

Here’s Our Approach

Stage 1

Firstly we create a variable for our wind up time. Then we create a repeat while true loop so that our wind up and wind down code will repeat. Inside the loop we add an IF statement with the condition that checks the most important detail, if our rover is upside down or not.

Stage 2

When the rover is upside down we set all LEDs red and begin increasing the wind up time. We do this by adding 1 and then delaying our code for 1 second. This means each second our variable wind up time increases by 1.

Stage 3

When our rover is right way up and the wind up time is greater than zero we enter the unwinding branch. Firstly we set our LEDs green. Then we do our sound and motor commands (feel free to do your own thing here). We then decrease wind up time by 1 and delay. Once this reaches 0 we will enter the ELSE branch where we turn everything off.

Example Code

 

Related Posts

Previous
Previous

Activity: Balance Bot

Next
Next

Activity: Lane Guidance