Measure How Far from Vertical or Level
In addition to the rotation angle with opposite and adjacent x and y values, your projects can calculate the triangle’s hypotenuse to determine how far from vertical the micro:bit has been tilted.
Example project: rotate_angle_with_degree_of_tilt
- Enter this project and name it rotate_angle_with_degree_of_tilt.
- Flash the project into the micro:bit.
- Open the terminal.
- Hold the micro:bit vertical and pick a rotation angle, like 60°.
- Note the angle and hyp values.
- Start holding the micro:bit vertically, rotated at 45 degrees. Make a note of the hyp variable value. It should be near 1024.
Tilt it 45° degrees away from you (toward level) while keeping the rotation at 45°. The angle should stay the same, but the hyp variable should report a smaller value.
Continuing to hold the rotation at 45°, tilt it a little further toward level. Did the hyp variable value get even smaller?