#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
Dim lcd As LiquidCrystal 'rLiquidCrystal must be enabled in the B4R IDE
Dim bitmap As LcdBitmap 'rLCDBitmap must be enabled in the B4R IDE
Dim t As Timer
Dim cnt As Byte = 0
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
t.Initialize("t_tick", 4000)
lcd.Initialize(8,255,9, Array As Byte(4,5,6,7)) 'initialize the LCD (rLiquidCrystal) library
lcd.Begin(16,2)
bitmap.Initialize(lcd, 0, 0)
bitmap.begin
lcd.SetCursor(7, 0)
lcd.Write("LCDGraph")
t.Enabled = True
End Sub
Sub t_tick
'A short explanation:
'"bars" must be a factor of 20 (i.e 1, 2, 4, 5, 10, or 20)
'On the LCD display you can draw a graph of 4 columns x 2 rows (i.e 4x5=20 pixels wide and 2x8=16 pixels high
'If "bars" is set to 1 then all 4 columns will display the same height value
'If "bars" is set to 2 then 2 LCD "chars" wide x 2 LCD "chars" high will display 2 x y values
'If "bars" is set to 4 then 4 LCD "chars" wide x 2 LCD "chars" high will display 4 x y values
'If "bars" is set to 5 then 4 LCD pixels rows (wide) x 2 LCD "chars" high will display 5 x y values
'If "bars" is set to 10 then 2 LCD pixels rows (wide) x 2 LCD "chars" high will display 10 x y values
'If "bars" is set to 20 then 1 LCD pixel rows (wide) x 2 LCD "chars" high will display 20 x y values
'Watch the below code being executed on the display to see what I mean in the above explanation
If cnt = 0 Then
Dim bars As Byte = 1 'set to factors of 20 (1, 2, 4, 5, 10, 20) - 20 pixels wide
Dim graph(bars) As Byte
Dim x As Byte
For x = 0 To bars - 1
graph(x) = Rnd(0, bitmap.BitmapH - 1) 'bitmap.BitmapH = height = 16 by default
Next
bitmap.barGraph(bars, graph, bitmap.COLOR_ON, bitmap.UPDATE_ON)
cnt = cnt + 1
else if cnt = 1 Then
Dim bars As Byte = 2 'set to factors of 20 (1, 2, 4, 5, 10, 20)
Dim graph(bars) As Byte
Dim x As Byte
For x = 0 To bars - 1
graph(x) = Rnd(0, bitmap.BitmapH - 1)
Next
bitmap.barGraph(bars, graph, bitmap.COLOR_ON, bitmap.UPDATE_ON)
cnt = cnt + 1
else if cnt = 2 Then
Dim bars As Byte = 4 'set to factors of 20 (1, 2, 4, 5, 10, 20)
Dim graph(bars) As Byte
Dim x As Byte
For x = 0 To bars - 1
graph(x) = Rnd(0, bitmap.BitmapH - 1)
Next
bitmap.barGraph(bars, graph, bitmap.COLOR_ON, bitmap.UPDATE_ON)
cnt = cnt + 1
else if cnt = 3 Then
Dim bars As Byte = 5 'set to factors of 20 (1, 2, 4, 5, 10, 20)
Dim graph(bars) As Byte
Dim x As Byte
For x = 0 To bars - 1
graph(x) = Rnd(0, bitmap.BitmapH - 1)
Next
bitmap.barGraph(bars, graph, bitmap.COLOR_ON, bitmap.UPDATE_ON)
cnt = cnt + 1
else if cnt = 4 Then
Dim bars As Byte = 10 'set to factors of 20 (1, 2, 4, 5, 10, 20)
Dim graph(bars) As Byte
Dim x As Byte
For x = 0 To bars - 1
graph(x) = Rnd(0, bitmap.BitmapH - 1)
Next
bitmap.barGraph(bars, graph, bitmap.COLOR_ON, bitmap.UPDATE_ON)
cnt = cnt + 1
else if cnt = 5 Then
Dim bars As Byte = 20 'set to factors of 20 (1, 2, 4, 5, 10, 20)
Dim graph(bars) As Byte
Dim x As Byte
For x = 0 To bars - 1
graph(x) = Rnd(0, bitmap.BitmapH - 1)
Next
bitmap.barGraph(bars, graph, bitmap.COLOR_ON, bitmap.UPDATE_ON)
cnt = cnt + 1
End If
If cnt = 6 Then cnt = 0
End Sub