@@ -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,15 +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;
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
-
104
99
// Instruction: Set DDRAM address = 0x80
105
- _send (0x80 | (row_offsets [row] + col));
100
+ _send (0x80 | (_row_offsets [row] + col));
106
101
} // setCursor()
107
102
108
103
@@ -284,4 +279,24 @@ void LiquidCrystal_PCF8574::_write2Wire(int halfByte, bool isData, bool enable)
284
279
Wire.endTransmission ();
285
280
} // write2Wire
286
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
+
287
302
// The End.
0 commit comments