Skip to content

Commit 224b7e7

Browse files
authored
Update LiquidCrystal_PCF8574.cpp
1 parent 4bade02 commit 224b7e7

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/LiquidCrystal_PCF8574.cpp

+24-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LiquidCrystal_PCF8574::LiquidCrystal_PCF8574(int i2cAddr)
3333

3434
void LiquidCrystal_PCF8574::begin(int cols, int lines)
3535
{
36-
(void)cols; // ignored !
36+
_cols = cols;
3737
_lines = lines;
3838

3939
int functionFlags = 0;
@@ -66,6 +66,8 @@ void LiquidCrystal_PCF8574::begin(int cols, int lines)
6666
display();
6767
clear();
6868
leftToRight();
69+
70+
_row_offsets = _getRowOffsets();
6971
} // begin()
7072

7173

@@ -94,15 +96,8 @@ void LiquidCrystal_PCF8574::home()
9496
/// Set the cursor to a new position.
9597
void LiquidCrystal_PCF8574::setCursor(int col, int row)
9698
{
97-
int *row_offsets;
98-
99-
if (this->_lines == 4)
100-
row_offsets = new int[4] {0x00, 0x40, 0x10, 0x50};
101-
else
102-
row_offsets = new int[4] {0x00, 0x40, 0x14, 0x54};
103-
10499
// Instruction: Set DDRAM address = 0x80
105-
_send(0x80 | (row_offsets[row] + col));
100+
_send(0x80 | (_row_offsets[row] + col));
106101
} // setCursor()
107102

108103

@@ -284,4 +279,24 @@ void LiquidCrystal_PCF8574::_write2Wire(int halfByte, bool isData, bool enable)
284279
Wire.endTransmission();
285280
} // write2Wire
286281

282+
// Prepare row_offsets
283+
int* LiquidCrystal_PCF8574::_getRowOffsets()
284+
{
285+
int *row_offsets = new int[this->_lines];
286+
287+
if (this->_lines > 0)
288+
row_offsets[0] = 0x00;
289+
else if (this->_lines > 1)
290+
row_offsets[1] = 0x40;
291+
else if (this->_lines > 2)
292+
{
293+
for (int i = 0, j = 2; j < this->_lines; i++, j++)
294+
{
295+
row_offsets[j] = row_offsets[i] + _cols;
296+
}
297+
}
298+
299+
return row_offsets;
300+
}
301+
287302
// The End.

0 commit comments

Comments
 (0)