---
title: "Activity: Wind-up Rover"
date: "2021-06-03"
categories: ["Activities", "All"]
tags: ["Iteration", "Variables", "Accelerometer", "Motors", "Maths", "Intermediate"]
codingSkills: ["Iteration", "Variables", "Maths"]
roverConcepts: ["Accelerometer", "Motors"]
excerpt: "Learn iteration, variables, maths, and how to use the Rover’s motors and accelerometer."
featuredImage: "/images/resources/windup-rover.jpg"
---


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.

### Activity Demonstration

<iframe width="560" height="315" src="https://www.youtube.com/embed/Y-lzGxjS-og" title="Wind-up Rover Activity Demonstration" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>

### 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.

![](/images/content/30edb3-screenshot-2023-10-31-083156.png)

Example Code
