New B4A remote with JoystickView

Marc DANIEL

Well-Known Member
Licensed User
Longtime User
Hello everyone. I have replaced my old B4A remote control with a new application that uses JoystickView, without needing to modify the B4R application installed on the ARDUINO-based vehicle, which is controlled via the Bluetooth system of an Android smartphone.

B4X: Copy
Sub Joystick1_onMove (Angle As Double, Pow As Double)
    Cap = Joystick1.AngleDegrees
    Log("ANGLE: " & Angle)
    Log("Angle in degrees: " & Cap)
    Log("Power: "& Pow)
    If Pow < 25 Then 'dead zone to prevent unintended movements
        'Angle cutting (0 to + or - 180°) to define the direction to take
        'If Cap > 25 And Cap < 90 Then
        'End If
   
    Else if Cap > 45 And Cap < 135 Then
        Log("Angle in degrees: " & Cap)
        If Pow > 40 And Pow < 80 Then Order = 10 : Direction = "Forward"
        If Pow > 80 Then Order = 11 : Direction = "Fast Forward"
        Log("Direction: " & Direction)
   
    Else if Cap < -45 And Cap > -135 Then
        Log("Angle in degrees: " & Cap)
        If Pow > 40 And Pow < 80 Then Order = 12 : Direction ="Backward"
        If Pow > 80 Then Order = 13 : Direction = "Fast Reverse"
        Log("Direction: " & Direction)
   
    Else if Cap < 37 And Cap > -45 Then
        Log("Angle in degrees: " & Cap)
        If Pow > 40 And Pow <80 Then Direction = "Turn right" : Order = 4
        If Pow > 80 Then Order = 5 : Direction ="turn sharply to the right"
        Log("Direction: " & Direction)
   
    Else if Cap > 135 And Cap > -135 Then
        Log("Angle in degrees: " & Cap)
        If Pow > 40 And Pow <80 Then Direction = "Turn left" : Order = 6
        If Pow > 80 Then Order = 7 : Direction ="turn sharply to the left"
        Log("Direction: " & Direction)
   
    else if Pow < 40 Then
        Direction = "STOP" : Order = 0
        Log("Direction: " & Direction)
    End If
    ' FILTER: AVOID DUPLICATES : The byte is sent ONLY if the direction has changed.
    If Order <> LastOrderSent Then
        LastOrderSent = Order
        B4XPages.MainPage.BTA.Write(Array As Byte(Order))
    End If
End Sub

Old app

APK.file
B4A files



Bluetooth_Search_Screenshot.png


Bluetooth Search Screenshot

Arduino_Vehicle_Screenshot.png


Arduino Vehicle Orders

​
 
Last edited:
Back
Top