You can combine the xy calculated angle from Measuring Rotation Angles [1] with the z angle introduced here to get a complete picture of how the micro:bit is oriented in space.
Example script: z_axis_and_xy_axis_angles_your_turn
# z_axis_and_xy_axis_angles_your_turn from microbit import * import math sleep(1000) while True: x = accelerometer.get_x() y = accelerometer.get_y() z = accelerometer.get_z() xy_angle = round( math.degrees( math.atan2(y, x) ) ) if z > 1024: z = 1024 elif z < -1024: z = -1024 z_angle = round( math.degrees( math.acos( z/1024) ) ) print("z_angle =", z_angle) print("xy_angle =", xy_angle) print() sleep(750)
Links
[1] https://learn.parallax.com/tutorials/robot/cyberbot/cybersecurity-radio-tilt-control/measure-rotation-angles/measuring-rotation