@@ -33,7 +33,7 @@ LiquidCrystal_PCF8574::LiquidCrystal_PCF8574(int i2cAddr)
33
33
34
34
void LiquidCrystal_PCF8574::begin (int cols, int lines)
35
35
{
36
- ( void )cols; // ignored !
36
+ _cols = cols;
37
37
_lines = lines;
38
38
39
39
int functionFlags = 0 ;
@@ -66,6 +66,8 @@ void LiquidCrystal_PCF8574::begin(int cols, int lines)
66
66
display ();
67
67
clear ();
68
68
leftToRight ();
69
+
70
+ _row_offsets = _getRowOffsets ();
69
71
} // begin()
70
72
71
73
@@ -94,9 +96,8 @@ void LiquidCrystal_PCF8574::home()
94
96
// / Set the cursor to a new position.
95
97
void LiquidCrystal_PCF8574::setCursor (int col, int row)
96
98
{
97
- int row_offsets[] = {0x00 , 0x40 , 0x14 , 0x54 };
98
99
// Instruction: Set DDRAM address = 0x80
99
- _send (0x80 | (row_offsets [row] + col));
100
+ _send (0x80 | (_row_offsets [row] + col));
100
101
} // setCursor()
101
102
102
103
@@ -278,4 +279,24 @@ void LiquidCrystal_PCF8574::_write2Wire(int halfByte, bool isData, bool enable)
278
279
Wire.endTransmission ();
279
280
} // write2Wire
280
281
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
+
281
302
// The End.
0 commit comments