'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Dim controller As GpioController
Dim timer1 As Timer
Dim lcd As JavaObject
Dim handle As Int
Dim MyText,ScrollingText As String
Dim TextChar, Col As Int
End Sub
Sub AppStart (Args() As String)
controller.Initialize
lcd.InitializeStatic("com.pi4j.wiringpi.Lcd")
timer1.Initialize("timer1",300)
'int lcdInit(int rows, int cols, int bits, int rs, int strb, int d0, int d1, int d2, int d3, int d4,
' int d5, int d6, int d7);
handle= lcd.RunMethod("lcdInit", Array(2,16,4,1,2,3,4,5,6,0,0,0,0))
lcd.RunMethod("lcdClear", Array(handle))
'lcd.RunMethod("lcdPosition", Array(handle, 0,0))
'lcd.RunMethod("lcdPuts", Array(handle, "Test LCD on Rpi"))
'lcd.RunMethod("lcdPosition", Array(handle, 0,1))
'lcd.RunMethod("lcdPuts", Array(handle, "Pi4j with B4J"))
MyText="This is scrolling text, it is quite long!"
TextChar=0 ' Start with first character in MyText
Col=16 ' Start position on LCD, scroll right to left.
ScrollingText=MyText.SubString2(TextChar,TextChar+1) ' Get first character of string
timer1.Enabled=True
StartMessageLoop ' Comment if don't want to run continiously
End Sub
Sub timer1_Tick
'Log("Col: " & Col & " ,TextChar: " & TextChar & " ,Scrolling Text = " & ScrollingText)
lcd.RunMethod("lcdClear", Array(handle))
lcd.RunMethod("lcdPosition", Array(handle, Col,0)) 'Horizontal scroll in row 1
lcd.RunMethod("lcdPuts", Array(handle, ScrollingText))
' Stop
If TextChar=MyText.Length Then
timer1.Enabled=False
ExitApplication
End If
If Col>0 Then 'If we are not in column 1 then add more characters
Col=Col-1
ScrollingText=MyText.SubString2(0,16-Col)
Else
TextChar=TextChar+1 'otherwise, change the start position in substring.
If TextChar+16<MyText.Length Then
ScrollingText=MyText.SubString2(TextChar,TextChar+16)
Else
ScrollingText=MyText.SubString2(TextChar,MyText.Length)
End If
End If
End Sub