Mathematics Microbit
Normal
60 mins
200 points
What you need:
• Computer/laptop

# Microbit Toothbrush Timer

In this project you will turn your microbit into a toothbrush timer! Dentists recommend that you brush your teeth for 2 minutes so we will program our microbits to count 2 minutes and tell us how much time has elapsed and when to switch from your top teeth to your bottom teeth!

### 2 - Create a 'seconds' variable

We're going to count to 2 minutes (or 120 seconds) so we need a variable to store the seconds as they tick by.

Create a variable called 'seconds'.

### 3 - Display an arrow

To start the toothbrush timer you will need to press the A button. So we will show an arrow pointing left (west) at the start. This will point at the A button.

You will find these blocks in the Advanced > Images toolbox.

Note: Change the arrow image to West (North is displayed in the code below).

```images.arrowImage(ArrowNames.West).showImage(0)

```

### 4 - Count to 120 seconds

Next we will program the A button to set the 'seconds' variable to 0 and then count to 120.

We do this by using a 'while' loop block. While the 'seconds' variable is less than or equal to 120, pause 1 second and then add 1 to the 'seconds' variable. This will keep adding 1 to the 'seconds' variable until it reaches 120.

```input.onButtonPressed(Button.A, function () {
seconds = 0
while (seconds <= 120) {
basic.pause(1000)
seconds += 1
}
})

```

### 5 - Add an 'if then else'

We're going to check how many seconds have passed and display a graph using the LEDs to show how many have.

To do this we first need to add an 'if then else' block inside the 'forever' block. We then use the plus button on the 'if then else' block to set it up like below:

```basic.forever(function () {
if (true) {

} else if (false) {

} else if (false) {

} else if (false) {

}
})

```