First post to this forum but I think I know what I am talking about (you can correct me if you want, I can take it).
I setup an Arduino with a 16x2 display and all works great.
I found a 20x4, hooked it up and things all worked OK.
Next I had a few 16x4 and plugged one in and things did not line up properly.
Looking at the code:
void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
if ( row > _numlines ) {
row = _numlines-1; // we count rows starting w/0
}
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
Notice that the offset does not change based on characters per line (no way of knowing).
Not sure if this is 'clean' bit it worked for me.
Needed a place to save number of characters so in Begin I added:
void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
if (lines > 1) {
_displayfunction |= LCD_2LINE;
}
_numlines = lines;
_numcols = cols;
_currline = 0;
Then in setCursor I added/changed it like this:void LiquidCrystal::setCursor(uint8_t col, uint8_t row)
{
// 16 Cols int row_offsets[] = { 0x00, 0x40, 0x10, 0x50 };
// 20 Cols int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
int row_offsets[] = { 0x00, 0x40, 0x10, 0x50 };
if(_numcols == 20) {
row_offsets[2] = 0x14;
row_offsets[3] = 0x54;
}
if ( row > _numlines ) {
row = _numlines-1; // we count rows starting w/0
}
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}
It now works for me with 16x2, 16x4, 20x2 and 20x4. It only changed the 4 line displays. I don't see any reason it will mess anything else up.
Any comments? How do we get this into the lib if no one else see problems in it?
Thanks
Tim