02.
Step 2: Select 'Continue with Google'.
03.
Step 3: Select your school account.
04.
Step 4: Select 'Continue'
05.
Step 5: Select 'New Project' and name your project "Inclinometer"
Click 'Create' to save.
06.
Step 6: Select any existing blocks and delete them.
07.
Step 7: From the toolbox, select the Input category and drag the block 'On Button 'A' Pressed' into the work area.
08.
Step 8: Click on the Variables category in the Toolbox:
Create a new variable called 'Angle'.
Select the 'set Angle to' block and drag this into the input block.
09.
Step 9: Select the Input category and then select the '...more' option.
Select the 'rotation (*) pitch' block and drag this into the angle block as shown.
10.
Step 10: Click on the Basic category in the Toolbox:
Drag a 'show number' block out and drop it under the set angle block as shown.
11.
Step 11: Click on the Variables category in the Toolbox.
Drag the 'Angle' variable block out and drop it in the 'show number' block as shown.
Button A Pressed:
input.onButtonPressed(Button.A, function () { ... }): This means that when you press button A, the code inside the curly braces will run.
angle = input.rotation(Rotation.Pitch): This line gets the current tilt angle (pitch) of the micro:bit and saves it in the angle variable.
basic.showNumber(angle): This shows the angle on the micro:bit's display.
12.
Step 12: Go to the Input toolbox and drag the block 'On Button 'A' Pressed' into the work area.
Use the dropdown arrow to change button A to button B.
13.
Step 13: Go to the Variables category in the Toolbox:
Create a new variable called 'Distance'.
Select the 'set Distance to' block and drag this into the input block as shown.
14.
Step 14: Go to the Variables category in the Toolbox:
Create a new variable called 'Height'.
Select the 'set Height to' block and drag this below the distance block as shown.
15.
Step 15: Go to the Basic category in the Toolbox:
Drag a 'show number' block out and drop it under the set height block as shown.
16.
Step 16: Go to the Math category in the Toolbox:
Drag a 'round' block into the 'show number' block as shown.
17.
Step 17: Go to the Math category in the Toolbox:
Drag a '0 + 0' block into the 'round' number block on the right side.
Click on the 'Height' and drag this into the number box on the right side of the + (plus).
18.
Step 18: Go to the Math category in the Toolbox.
Drag a '0 x 0' block into the left 'round' number block on the left side.
Click on 'Distance' and drag this into the number box on the left side of the x (multiply).
19.
Step 19: Go to the Math category in the Toolbox.
Drag a square root block next to the x (multiply) symbol.
Use the dropdown menu to change this to tan.
20.
Step 20: Go to the Math category in the Toolbox.
Drag a '0 / 0' block next to Tan and then enter the number 180 in the right-hand digit box.
21.
Step 21: Go to the Math category in the Toolbox.
Drag a '0 x 0' block to the left of the '0 / 180' divide line.
Click on 'Angle' and drag this into the number box on the left side of the x (multiply).
22.
Step 22: Enter the number 3.142 to replace the zero.
Next to Distance input, enter the distance of 10 (metres).
Next to the Height input, enter the height of the eyeline of the person who will be using the inclinometer. As an example 1.80 (metres).
The code is now complete.
Variables:
set angle = 0: This starts off the angle at 0 degrees. It will later store the angle of tilt when button A is pressed.
set distance = 0: This is used to store a fixed distance (10 meters in this case).
set height = 0: This is used to store a height (1.85 meters, which could be the height of a person, for example).
Button B Pressed:
input.onButtonPressed(Button.B, function () { ... }): This means that when you press button B, the code inside these curly braces will run.
distance = 10: Here, it sets the distance to 10 meters.
height = 1.85: This sets the height to 1.85 meters.
basic.showNumber(Math.round(distance * Math.tan(angle * 3.142 / 180) + height)):
This line does a mathematical calculation:
It converts the angle from degrees to radians (since trigonometric functions in programming often use radians).
It calculates a new height based on the angle and distance using the tangent function, which is used in right triangles.
It adds this calculated height to the fixed height (1.85 meters).
Finally, it shows the rounded result on the display.
Clinometer Data: During the task, you and your partner will be required to record data. Download the form here