Gweithgaredd

# Distance calculator

Canolradd | MakeCode, Python | Botymau, Dangosydd LED, Logo cyffwrdd, Seinydd | Lluosi, Mesuriad, Newidynnau

## Cam 1: Gwneud

### Beth yw e?

Use your BBC micro:bit to measure distances as you walk.

### Beth fyddwch yn ei ddysgu

This practical project shows how to use multiplication and variables to measure distances.

### Sut mae'n gweithio

• Mae'r rhaglen hon yn cyfrifo pellteroedd trwy luosi hyd cam â nifer y camau a gymerwch. It uses an average child's step length of 0.6 metres.
• Carefully walk the distance you want to measure, pressing button A each time you take a step.
• The program works by increasing the 'step count' variable by one each time button A is pressed.
• Press button B to see the distance you have walked in metres. The micro:bit calculates this by multiplying the 'step count' variable by the step length.
• If you want to know how many steps you took, press the touch logo on the front of your micro:bit.
• Reset the micro:bit by pressing the reset button on the back.

### Beth sydd ei angen arnoch

• BBC micro:bit and battery pack

## Cam 2: codio

``````1# Imports go at the top
2from microbit import *
3import music
4
5stepcount = 0
6steplength = 0.6
7display.show(0)
8music.play(['c4:4'])
9
10while True:
11    if button_a.is_pressed():
12        music.play(['c3:2'])
13        display.show(Image.HEART)
14        sleep(400)
15        stepcount += 1
16        display.clear()
17    if button_b.is_pressed():
18        display.scroll(stepcount*steplength)
19    if pin_logo.is_touched():
20        display.scroll(stepcount)``````

## Cam 3: gwella

• Calculate your average step length in metres and use it to replace the 0.6 number in the code.
• Calculate areas of rectangles, such as parts of a school playground, by measuring each side and multiplying the distances together.
• Add cardboard to make the buttons easier to press, as seen in the Improve it section of the Emotion badge project.
• Use this wheelchair distance calculator code that can automatically detect when your wheel rotates. Replace the 0.6 number with the circumference of your wheel measured in metres.