Example:
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Public dissensor As SRF04 'Create Object
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
dissensor.Initialize(2,3) 'Initialize IO
Do While(True)
dissensor.Ranging 'Ranging
Log("Dis=",dissensor.GetDistance,"CM") 'Get Distance
Delay(2000)
Loop
End Sub