Android Question Help converting Xamarin inclinometer to B4X.

Dave G

Active Member
Licensed User
I've implemented an inclinometer in Xamarin Android that I'm trying to convert to B4X. The code fragment below is Xamarin C#. The device orientation examples I've found in the B4A forums haven't been much help as Azimuth in OrientationChanged or getRotation via Reflector don't seem to be what I'm looking for.

The parameter paOrientation represents the X axis angle of the device.

Xamarin C# snippet:
        private class OrientationListener : OrientationEventListener

        {

            Activity Activity { get; set; }



            public OrientationListener(Context context, SensorDelay delay, Activity activity) : base (context, delay)

            {

                Activity = activity;

            }

            public override void OnOrientationChanged(int paOrientation)

            {

                    ....

            }
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
even if it is not B4X Code you should use Code tags when posting code. C# is supported too btw ;-)
 
Last edited:
Upvote 0

Albert Kallal

Active Member
Licensed User
Ok, it not clear if you want a “event” to fire when you tilt the phone or you just want to “grab” the X axis value at any old time you please?

The "general"idea here is:

You wire up a stub that triggers when the phone is moved. This code will fire when the phone moves – will fire a lot!
You don’t care, since no UI occurs. This code will SET the x,y,z values for you. Runs constant - you don't care.

Then we have YOUR code!
I might read the value every 1/10th of a second, and update the display.

So, first part is to wire up the event stubs that automatic set our X, y, Z

o, the code would in theory look like this:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Accelerometer As PhoneAccelerometer

    Dim MyX            As Float
    Dim MyY            As Float
    Dim myZ            As Float
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume
    Accelerometer.StartListening("TiltChange")
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub TiltChange_AccelerometerChanged (X As Float, Y As Float, Z As Float)

    MyX = X
    MyY = Y
    myZ = Z
    
End Sub

Now, to be fair, I could have setup the MyX, myY, myZ as a class stub, but hey it just 3 values.

So, with the above then at all times, and at any time, I can grab the x value.

So we could add a view, drop in 3 label boxes, and have the screen update every 1/10th of a second.
Note how that the 2nd part of this code is a 100% separate idea and concept from the first part!

So, say we droped 3 labless on a view, and now want this to update every 10th of a second.

We would/could start a timer, and wind up with somthing like this:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Accelerometer As PhoneAccelerometer

    Dim MyTimer As Timer
    Dim MyX            As Float
    Dim MyY            As Float
    Dim myZ            As Float
        
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private Label4 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume
    Accelerometer.StartListening("TiltChange")
    MyTimer.Initialize("TimeTick",100)
    MyTimer.Enabled = True     <------- START our timer loop - it fires off code stub TimeTick
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub TiltChange_AccelerometerChanged (X As Float, Y As Float, Z As Float)

    MyX = X
    MyY = Y
    myZ = Z
    
End Sub

Sub TimeTick_Tick
   
    Label1.Text = MyX
    Label2.Text = MyY
    Label3.Text = myZ


End Sub

So, note how our TimeTick_Tick event stub just runs, and just grabs the current MyX value any time. You can even grab this value from OTHER activity - since it is a global variable.

So, break this down to two parts:
Wire up some code to ALWAYS setup the MyX, MyY, MyZ.

Once you done that, then any other code at any other time you want can always grab the current x,y,z values at will.
And such code would of course be some kind of timer or update-loop for your main display.

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Upvote 0

Dave G

Active Member
Licensed User
Thanks for taking the time to respond. I have a small proof of concept in B4A that does what you outlined. The issue is the X value that I get is not accurate or I'm not understanding it. I used your technique as well as two others and none delivered the value that I get from the Xamarin Android routine (paOrientation) that I provided above. The single value of paOrientation represents the x axis and I am able to convert that to proper angle depending on whether it's Portrait or Landscape. Here's a snippet from the Xamarin Anroid app that works:
Xamarin C# snippet:
                       if (curOrientation == "P")
                        {
                            if (paOrientation <= 45) {
                                lblAngle.Text = paOrientation.ToString();
                            } else if (paOrientation >= 315) {
                                lblAngle.Text = (360 - paOrientation).ToString();
                            } else if (paOrientation >= 180 && paOrientation <= 225) {
                                lblAngle.Text = (paOrientation - 180).ToString();
                            } else if (paOrientation >= 135 && paOrientation <= 180) {
                                lblAngle.Text = (180 - paOrientation).ToString();
                            }
                            else {
                                lblAngle.Text = "";
                                lblStatus.Text = "exceeds 45 degrees";
                            }
                        } else {
                            if (paOrientation <= 315 && paOrientation >= 270) {
                                lblAngle.Text = (paOrientation - 270).ToString();
                            } else if (paOrientation >= 225 && paOrientation <= 270) {
                                lblAngle.Text = (270 - paOrientation).ToString();
                            } else if (paOrientation >= 90 && paOrientation <= 135) {
                                lblAngle.Text = (paOrientation - 90).ToString();
                            } else if (paOrientation >= 45 && paOrientation <= 90) {
                                lblAngle.Text = (90 - paOrientation).ToString();
                            }
                            else {
                                lblAngle.Text = "";
                                lblStatus.Text = "exceeds 45 degrees";
                            }
                        }
 
Upvote 0

Albert Kallal

Active Member
Licensed User
My bad! - My Sorry.

I used PhoneAccelerometor - we want Phone Orenetation. My VERY sorry!

This code works:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim MyPhoneOrient As PhoneOrientation

    Dim MyTimer As Timer

    Dim MyAzimuth    As Float
    Dim MyPitch      As Float
    Dim myRoll       As Float

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private Label4 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume

    MyPhoneOrient.StartListening("TiltChange")
    MyTimer.Initialize("TimeTick",400)
    MyTimer.Enabled = True

End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub TiltChange_OrientationChanged(Azimuth As Float, Pitch As Float, Roll As Float)

    MyAzimuth = Azimuth
    MyPitch = Pitch
    myRoll = Roll

End Sub

Sub TimeTick_Tick

    Label1.Text = MyAzimuth
    Label2.Text = MyPitch
    Label3.Text = myRoll

End Sub

So, I created a view with 3 labels on it (generate the Dim label events by right clicking on the label, and choose Generate,- >dim Lable1 etc. for all 3.

Just as a FYI - the value of 10 being spit out is the acceleration of gravity - 10 meters per second! So, JUST holding the phone, you get a value of 10 since that is how hard gravity is pulling down on your phone! (and it is a vector - so if you hold the phone perfect vertical, then it spits out 10 for that vector!).

So, I typed in PhoneAccelerometer as opposed to PhoneOrientation. I just changed it to PhoneOrientation.

Give above a try - the values should be familiar and make sense now. My sorry for the goose chase!

Regards,
Albert D. Kallal
Edmonton, Alberta Canada
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hello @Dave G,
Wait a minute, are you saying that you have tried using the Phone library with the Orientation_OrientationChanged event sub and it was no good for you, whats exactly was the problem with it?
Logger connected to: Google Pixel 3 XL
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Azimuth = 49.15, Pitch=-88.79, Roll=-1.31
Azimuth = 48.78, Pitch=-88.25, Roll=-1.22
Azimuth = 48.34, Pitch=-88.71, Roll=-1.21
Azimuth = 48.06, Pitch=-88.98, Roll=-1.2
Azimuth = 47.16, Pitch=-88.37, Roll=-1.38
Azimuth = 47.04, Pitch=-88.14, Roll=-1.52
Azimuth = 47.16, Pitch=-88.27, Roll=-1.14
Azimuth = 46.98, Pitch=-88.38, Roll=-1.16
Azimuth = 46.94, Pitch=-88.32, Roll=-1.11
Azimuth = 46.86, Pitch=-88.49, Roll=-1.11
Azimuth = 46.76, Pitch=-88.62, Roll=-1.12
Azimuth = 46.57, Pitch=-88.7, Roll=-1.13
Azimuth = 46.47, Pitch=-88.89, Roll=-1.15
Azimuth = 46.38, Pitch=-88.94, Roll=-1.15
Azimuth = 46.28, Pitch=-89.01, Roll=-1.15
Azimuth = 46.27, Pitch=-88.98, Roll=-1.14
Azimuth = 46.19, Pitch=-88.98, Roll=-1.14
Azimuth = 46.11, Pitch=-89.05, Roll=-1.14
Azimuth = 45.96, Pitch=-89.06, Roll=-1.16
Azimuth = 45.89, Pitch=-89.05, Roll=-1.15
Azimuth = 45.84, Pitch=-89.07, Roll=-1.16
Azimuth = 45.76, Pitch=-89.05, Roll=-1.16
Azimuth = 45.74, Pitch=-89.05, Roll=-1.16
Azimuth = 45.75, Pitch=-89.07, Roll=-1.15
Azimuth = 45.73, Pitch=-89.06, Roll=-1.09
Azimuth = 45.66, Pitch=-89.1, Roll=-1.1
Azimuth = 45.7, Pitch=-89.09, Roll=-1.12
Azimuth = 45.69, Pitch=-89.14, Roll=-1.13
Azimuth = 45.63, Pitch=-89.11, Roll=-1.12
Azimuth = 45.57, Pitch=-89.11, Roll=-1.12
Azimuth = 45.54, Pitch=-89.1, Roll=-1.11
Azimuth = 45.5, Pitch=-89.11, Roll=-1.1
Azimuth = 45.59, Pitch=-89.15, Roll=-0.99
Azimuth = 45.59, Pitch=-89.21, Roll=-0.51
Azimuth = 45.81, Pitch=-89.12, Roll=0.26
Azimuth = 45.82, Pitch=-89.02, Roll=1.48
Azimuth = 45.94, Pitch=-88.87, Roll=3.03
Azimuth = 45.83, Pitch=-88.67, Roll=4.1
Azimuth = 45.36, Pitch=-88.74, Roll=4.55
Azimuth = 44.18, Pitch=-88.86, Roll=4.9
Azimuth = 43.48, Pitch=-88.94, Roll=5.05
Azimuth = 43.2, Pitch=-89.05, Roll=5.06
Azimuth = 43.7, Pitch=-88.89, Roll=5.49
Azimuth = 44.03, Pitch=-88.73, Roll=6.31
Azimuth = 44, Pitch=-88.52, Roll=7.68
Azimuth = 44.16, Pitch=-88.27, Roll=8.83
Azimuth = 44.14, Pitch=-88.48, Roll=10.06
Azimuth = 44.65, Pitch=-88.45, Roll=11.6
Azimuth = 44.71, Pitch=-88.25, Roll=12.83
Azimuth = 44.42, Pitch=-87.67, Roll=14.06
Azimuth = 43.92, Pitch=-87.81, Roll=15.39
Azimuth = 44.05, Pitch=-88.14, Roll=17.08
Azimuth = 44.4, Pitch=-87.96, Roll=18.99
Azimuth = 44.9, Pitch=-87.74, Roll=21.14
Azimuth = 45.7, Pitch=-87.68, Roll=22.78
Azimuth = 46.02, Pitch=-87.88, Roll=23.88
Azimuth = 46.85, Pitch=-88.44, Roll=25.42
Azimuth = 47.4, Pitch=-88.92, Roll=27.23
Azimuth = 48.25, Pitch=-89.57, Roll=28.85
Azimuth = 48.93, Pitch=-89.86, Roll=30.33
Azimuth = 48.59, Pitch=-89.95, Roll=31.62
Azimuth = 48.62, Pitch=-90.15, Roll=33.02
Azimuth = 49.89, Pitch=-91.16, Roll=34.47
Azimuth = 51.04, Pitch=-92.23, Roll=36.06
Azimuth = 51.77, Pitch=-92.66, Roll=38.36
Azimuth = 51.57, Pitch=-92.16, Roll=41.03
Azimuth = 51.51, Pitch=-92.85, Roll=43.42
Azimuth = 50.44, Pitch=-92.6, Roll=45.63
Azimuth = 49.64, Pitch=-92.6, Roll=47.51
Azimuth = 49.42, Pitch=-92.35, Roll=48.69
Azimuth = 49.35, Pitch=-92.45, Roll=48.96
Azimuth = 48.95, Pitch=-92.37, Roll=49.27
Azimuth = 48.31, Pitch=-92.15, Roll=49.33
Azimuth = 48.24, Pitch=-92.17, Roll=49.56
Azimuth = 48.35, Pitch=-92.14, Roll=50.26
Azimuth = 48.05, Pitch=-91.9, Roll=51.58
Azimuth = 47.96, Pitch=-92.15, Roll=53.92
Azimuth = 47, Pitch=-92.5, Roll=56.5
Azimuth = 48.13, Pitch=-94.14, Roll=60.01
Azimuth = 48.73, Pitch=-94.93, Roll=63.61
Azimuth = 50.93, Pitch=-96.9, Roll=67.35
Azimuth = 51.78, Pitch=-97.6, Roll=71.03
Azimuth = 52.06, Pitch=-98.25, Roll=73.21
Azimuth = 53.14, Pitch=-99.64, Roll=74.84
Azimuth = 55.76, Pitch=-101.97, Roll=76.46
Azimuth = 57.23, Pitch=-103.29, Roll=78
Azimuth = 55.65, Pitch=-102.13, Roll=79.18
Azimuth = 48.46, Pitch=-95.73, Roll=80.19
Azimuth = 36.69, Pitch=-84.78, Roll=82.27
Azimuth = 21.85, Pitch=-70.3, Roll=83.58
Azimuth = 13.09, Pitch=-61.91, Roll=84.12
Azimuth = 0.54, Pitch=-49.98, Roll=84.49
Azimuth = 349.52, Pitch=-39.49, Roll=84.84
Azimuth = 340.38, Pitch=-30.82, Roll=84.95
Azimuth = 323.82, Pitch=-14.98, Roll=84.68
Azimuth = 314.48, Pitch=-5.96, Roll=84.3
Azimuth = 312.84, Pitch=-4.78, Roll=84.96
Azimuth = 312.37, Pitch=-4.51, Roll=85.16
Azimuth = 311.93, Pitch=-4.37, Roll=85.71
Azimuth = 312.38, Pitch=-4.87, Roll=86.01
Azimuth = 312.81, Pitch=-5.31, Roll=86.18
Azimuth = 312.97, Pitch=-5.5, Roll=86.29
Azimuth = 313.18, Pitch=-5.72, Roll=86.31
Azimuth = 313.25, Pitch=-5.82, Roll=86.36
Azimuth = 313.4, Pitch=-5.99, Roll=86.42
Azimuth = 313.35, Pitch=-5.94, Roll=86.4
Azimuth = 313.31, Pitch=-5.95, Roll=86.41
Azimuth = 313.33, Pitch=-5.98, Roll=86.42
Azimuth = 313.36, Pitch=-6.02, Roll=86.42
Azimuth = 313.22, Pitch=-5.93, Roll=86.45
Azimuth = 313.28, Pitch=-6.01, Roll=86.45
Azimuth = 313.02, Pitch=-5.76, Roll=86.44
Azimuth = 312.95, Pitch=-5.73, Roll=86.5
Azimuth = 312.98, Pitch=-5.79, Roll=86.68
Azimuth = 310.87, Pitch=-3.62, Roll=86.53
Azimuth = 306.7, Pitch=0.59, Roll=86.51
Azimuth = 306.68, Pitch=0.54, Roll=86.63
Azimuth = 301.19, Pitch=6.18, Roll=86.58
Azimuth = 301.08, Pitch=6.27, Roll=86.6
Azimuth = 299.93, Pitch=7.4, Roll=86.69
Azimuth = 296.91, Pitch=10.46, Roll=86.66
Azimuth = 297.06, Pitch=10.3, Roll=86.66
Azimuth = 298.13, Pitch=9.21, Roll=86.63
Azimuth = 298.54, Pitch=8.79, Roll=86.64
Azimuth = 296.89, Pitch=10.46, Roll=86.65
Azimuth = 293.95, Pitch=13.43, Roll=86.73
Azimuth = 288.31, Pitch=19.16, Roll=86.52
Azimuth = 283.93, Pitch=23.57, Roll=86.47
Azimuth = 278.68, Pitch=28.9, Roll=86.39
Azimuth = 273.17, Pitch=34.54, Roll=86.18
Azimuth = 270.36, Pitch=37.23, Roll=86.36
Azimuth = 267.51, Pitch=40.12, Roll=86.3
Azimuth = 265.58, Pitch=42.06, Roll=86.22
Azimuth = 262.8, Pitch=44.89, Roll=86.08
Azimuth = 259.98, Pitch=47.74, Roll=85.9
Azimuth = 257.14, Pitch=50.69, Roll=85.6
Azimuth = 253.34, Pitch=54.58, Roll=85.36
Azimuth = 250.73, Pitch=57.16, Roll=85.35
Azimuth = 248.91, Pitch=59.13, Roll=85
Azimuth = 248.5, Pitch=59.63, Roll=84.84
Azimuth = 244.95, Pitch=63.14, Roll=84.85
Azimuth = 245.09, Pitch=62.97, Roll=84.87
Azimuth = 244.37, Pitch=63.65, Roll=84.91
Azimuth = 239.16, Pitch=69.14, Roll=84.31
Azimuth = 233.83, Pitch=74.42, Roll=83.92
Azimuth = 226.68, Pitch=81.27, Roll=83.69
Azimuth = 229.11, Pitch=78.97, Roll=83.3
Azimuth = 229.25, Pitch=78.88, Roll=83.07
Azimuth = 227.58, Pitch=80.64, Roll=82.36
Azimuth = 227.02, Pitch=81.4, Roll=81.06
Azimuth = 226.59, Pitch=81.72, Roll=81.25
Azimuth = 228.55, Pitch=79.75, Roll=81.97
Azimuth = 226.73, Pitch=81.05, Roll=85.4
Azimuth = 224.91, Pitch=82.54, Roll=88.89
Azimuth = 20.75, Pitch=-73.64, Roll=89.48
Azimuth = 59.99, Pitch=-112.93, Roll=89.45
Azimuth = 63.11, Pitch=-116.08, Roll=89.4
Azimuth = 76.28, Pitch=-129.26, Roll=89.28
Azimuth = 78.04, Pitch=-131.03, Roll=89.26
Azimuth = 84.07, Pitch=-137.07, Roll=89.18
Azimuth = 86.1, Pitch=-139.11, Roll=89.14
Azimuth = 87.95, Pitch=-140.96, Roll=89.1
Azimuth = 84.07, Pitch=-137.09, Roll=89.15
Azimuth = 73.27, Pitch=-126.31, Roll=89.26
Azimuth = 83.64, Pitch=-136.68, Roll=89.12
Azimuth = 88.37, Pitch=-141.42, Roll=89.02
Azimuth = 94.72, Pitch=-147.79, Roll=88.85
Azimuth = 91.26, Pitch=-144.51, Roll=88.84
Azimuth = 50.54, Pitch=-103.75, Roll=87.54
Azimuth = 32.84, Pitch=-86.31, Roll=84.11
Azimuth = 28.18, Pitch=-81.96, Roll=80.09
Azimuth = 29.46, Pitch=-83.07, Roll=76.02
Azimuth = 28.83, Pitch=-82.73, Roll=72
Azimuth = 31.17, Pitch=-85.78, Roll=68.02
Azimuth = 32.33, Pitch=-87.65, Roll=64.12
Azimuth = 32.99, Pitch=-88.53, Roll=60.01
Azimuth = 33.38, Pitch=-88.68, Roll=56.63
Azimuth = 32.78, Pitch=-87.85, Roll=53.55
Azimuth = 31.97, Pitch=-87.1, Roll=50.91
Azimuth = 32.49, Pitch=-87.26, Roll=48.91
Azimuth = 32.17, Pitch=-86.48, Roll=46.13
Azimuth = 30, Pitch=-84.69, Roll=41.31
Azimuth = 27.75, Pitch=-84.53, Roll=34.54
Azimuth = 29.44, Pitch=-87.28, Roll=27.41
Azimuth = 30.89, Pitch=-90, Roll=20.13
Azimuth = 32.16, Pitch=-91.95, Roll=14.45
Azimuth = 33.29, Pitch=-93.08, Roll=11.75
Azimuth = 34.06, Pitch=-93, Roll=9.68
Azimuth = 34.02, Pitch=-92.95, Roll=7.13
Azimuth = 34.26, Pitch=-93.23, Roll=5.27
Azimuth = 34.66, Pitch=-92.49, Roll=4.32
Azimuth = 34.91, Pitch=-92.11, Roll=3.47
Azimuth = 35.54, Pitch=-92.73, Roll=1.61
Azimuth = 38.97, Pitch=-91.31, Roll=-0.99
Azimuth = 38.98, Pitch=-91.27, Roll=-0.96
Logger connected to: Google Pixel 3 XL
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Roll=0.15%
Roll=0.08%
Roll=-0.09%
Roll=0.11%
Roll=0.15%
Roll=0.16%
Roll=0.06%
Roll=0.13%
Roll=0.16%
Roll=0.18%
Roll=0.26%
Roll=0.22%
Roll=0.18%
Roll=0.15%
Roll=0.28%
Roll=0.77%
Roll=1.9%
Roll=3.15%
Roll=4.01%
Roll=5.62%
Roll=7.21%
Roll=8.28%
Roll=9.14%
Roll=10.13%
Roll=11.36%
Roll=12.45%
Roll=14.26%
Roll=16.41%
Roll=18.69%
Roll=20.93%
Roll=22.58%
Roll=24.39%
Roll=25.28%
Roll=26.06%
Roll=28.05%
Roll=30.82%
Roll=32.97%
Roll=35.47%
Roll=37.93%
Roll=41%
Roll=43.08%
Roll=43.88%
Roll=44.42%
Roll=46.25%
Roll=48.49%
Roll=50.81%
Roll=52.56%
Roll=54.23%
Roll=55.35%
Roll=56.47%
Roll=57.6%
Roll=59.06%
Roll=60.52%
Roll=61.82%
Roll=63.25%
Roll=65.5%
Roll=66.73%
Roll=68.84%
Roll=70.97%
Roll=73.35%
Roll=74.7%
Roll=75.93%
Roll=77.25%
Roll=78.3%
Roll=80.16%
Roll=81.19%
Roll=82.13%
Roll=82.31%
Roll=82.01%
Roll=82.04%
Roll=82.86%
Roll=83.53%
Roll=83.79%
Roll=84.31%
Roll=84.42%
Roll=84.82%
Roll=84.88%
Roll=85.3%
Roll=85.34%
Roll=85.11%
Roll=85.18%
Roll=85.13%
Roll=85.33%
Roll=85.37%
Roll=85.13%
Roll=84.28%
Roll=84.2%
Roll=84.21%
Roll=84.08%
Roll=83.29%
Roll=83.2%
Roll=83.3%
Roll=83.76%
Roll=84.45%
Roll=84.39%
Roll=85%
Roll=83.68%
Roll=81.16%
Roll=79.85%
Roll=77.94%
Roll=76.03%
Roll=74.46%
Roll=72.41%
Roll=69.79%
Roll=67.38%
Roll=64.97%
Roll=61.83%
Roll=58.74%
Roll=55.83%
Roll=53.54%
Roll=52.15%
Roll=51.2%
Roll=49.46%
Roll=47.98%
Roll=45.73%
Roll=43.34%
Roll=40.24%
Roll=37.11%
Roll=34.11%
Roll=31.47%
Roll=27.68%
Roll=23.82%
Roll=21.45%
Roll=19.87%
Roll=17.54%
Roll=15.32%
Roll=12.8%
Roll=10.09%
Roll=7.91%
Roll=6.04%
Roll=4.77%
Roll=3.75%
Roll=1.81%
Roll=0.9%
Roll=1.1%
Roll=0.96%
Roll=0.95%
Roll=1%
Roll=1.07%
Roll=0.99%
Roll=0.96%
Roll=0.91%
Roll=0.94%
Roll=0.87%
Roll=0.92%
Roll=0.79%
Roll=0.85%
Roll=0.95%
Roll=0.94%
Roll=0.97%
Roll=0.96%
Roll=1.02%
Roll=0.97%
Roll=1%
Roll=0.97%
Roll=1.03%
Roll=1%
Roll=1.04%
Roll=1.02%
Roll=1.04%
Roll=1.03%
Roll=1.06%
Roll=1.03%
The roll is with the phone facing me, I then slowly change orientation from portrait to landscape and back again. I added sleep(250) to the event sub to slow things down a bit. With some simple coding this could easily be used to make a nice looking and functional inclinometer app.

As you already know, the phone library is excellent at gathering live data from device sensors.

Enjoy...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top