The attached project mimics this posting. Have added the basic functionality with inline C. It uses the rCore and rLiquidCrystal libraries.
Wiring diagram:
Result:
Sample code (change it to your licking):
There are most probably better ways to do this - but the lcd bar graph in the above/attached is working.
Wiring diagram:
Result:
Sample code (change it to your licking):
B4X:
'LCD Display - LCD 1602
'See attached wiring diagram
#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
Dim t As Timer
Dim maxvalue As Byte = 100
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
t.Initialize("t_Tick", 500)
lcd.Initialize(8,255,9, Array As Byte(4,5,6,7))
Delay(10)
lcd.Begin(16, 2)
lcd.Clear
RunNative("createOne",Null)
RunNative("createTwo",Null)
RunNative("createThree",Null)
RunNative("createFour",Null)
RunNative("createFive",Null)
lcd.SetCursor(0,0)
lcd.Write("B4R - LCD Graph")
Delay(3000)
lcd.SetCursor(0,1)
Delay(10)
RunNative("writeCharAlarm", 0)
t.Enabled = True
End Sub
Sub t_Tick
Dim i As Byte = Rnd(0, maxvalue + 1)
lcd.Clear
lcd.SetCursor(0,0)
lcd.Write("VALUE = ")
lcd.SetCursor(8,0)
lcd.Write(i)
lcd.SetCursor(0,1)
Dim full As Float = 16 * (i/maxvalue)
Dim ff As Int = full
Dim fraction As Int = Round(10 * (full - ff))
fraction = Round((fraction * 5 / 10))
For j = 1 To full
RunNative("writeCharAlarm", 4)
Next
If fraction = 1 Then
RunNative("writeCharAlarm", 0)
Else if fraction = 2 Then
RunNative("writeCharAlarm", 1)
Else if fraction = 3 Then
RunNative("writeCharAlarm", 2)
Else if fraction = 4 Then
RunNative("writeCharAlarm", 3)
End If
End Sub
#if C
Byte One[8] = {
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000,
B10000
};
byte Two[8] = {
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000,
B11000
};
Byte Three[8] = {
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100,
B11100
};
Byte Four[8] = {
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110,
B11110
};
Byte Five[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
void createOne(B4R::Object* o) {
b4r_main::_lcd->lc->createChar(0, One);
}
void createTwo(B4R::Object* o) {
b4r_main::_lcd->lc->createChar(1, Two);
}
void createThree(B4R::Object* o) {
b4r_main::_lcd->lc->createChar(2, Three);
}
void createFour(B4R::Object* o) {
b4r_main::_lcd->lc->createChar(3, Four);
}
void createFive(B4R::Object* o) {
b4r_main::_lcd->lc->createChar(4, Five);
}
void writeCharAlarm(B4R::Object* o) {
b4r_main::_lcd->lc->write((Byte)o->toULong());
}
#end if
There are most probably better ways to do this - but the lcd bar graph in the above/attached is working.