Micro:bit acceleration

Posted on
  • Hi everyone.
    I'm trying to write a code that give the acceleration of X axis and, if it's major than 45° something happens.
    Using

    Microbit.accel()
    

    I have a string like this

    { "x": 0.115234375, "y": -0.37109375, "z": -0.951171875 }
    

    First of all, what is this measure unit?
    How can I get degrees?
    And....is there a way to get X, Y and Z separately?

    Thanks

  • First of all, what is this measure unit?

    It's in g

    How can I get degrees?

    I believe this should work:

    var a = Microbit.accel();
    print(Math.atan2(a.x, a.y)*180/Math.PI)
    

    And....is there a way to get X, Y and Z separately?

    As above you can save to a variable and access each field separately, or even Microbit.accel().x will work

  • Thanks Gordon!
    I understand.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Micro:bit acceleration

Posted by Avatar for coat @coat

Actions