'-------------------------------------------------------------------------------
Option Explicit

'-------------------------------------------------------------------------------
Public Sub Main()

' This program reads a 2D acceleration vector and displays the angle between
' the vector and the X-axis.
'
'                      Y
' Coordinate system:   |
'                      +--X

    Dim Angle As Single, Ax As Single, Ay As Single
    Const RadianToDegree As Single = 57.29577951

    Call Init

    Do
        Call GetAngle(Angle)

        ' Convert to degrees and display.
        Debug.Print CStr( CInt(Angle * RadianToDegree) )
    Loop

End Sub
'-------------------------------------------------------------------------------
Private Sub GetAngle( _
    ByRef Angle As Single)

' Reads a 2D acceleration vector and returns the vector angle relative
' to the X axis. Angle is in radians.

    Dim Ax As Single, Ay As Single

    Call GetAccelerations(Ax, Ay)

    Call NormalizeVector(Ax, Ay)
    
    Angle = UnitVectorAngle(Ax, Ay)
    
End Sub
'-------------------------------------------------------------------------------
Private Sub Init()

    ' For calibration.
    Call GetPeriod

End Sub
'-------------------------------------------------------------------------------
