@@ -87,10 +87,11 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
8787 _displayfunction |= LCD_2LINE;
8888 }
8989 _numlines = lines;
90- _currline = 0 ;
90+
91+ setRowOffsets (0x00 , 0x40 , 0x00 + cols, 0x40 + cols);
9192
9293 // for some 1 line displays you can select a 10 pixel high font
93- if ((dotsize != 0 ) && (lines == 1 )) {
94+ if ((dotsize != LCD_5x8DOTS ) && (lines == 1 )) {
9495 _displayfunction |= LCD_5x10DOTS;
9596 }
9697
@@ -157,6 +158,14 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
157158
158159}
159160
161+ void LiquidCrystal::setRowOffsets (int row0, int row1, int row2, int row3)
162+ {
163+ _row_offsets[0 ] = row0;
164+ _row_offsets[1 ] = row1;
165+ _row_offsets[2 ] = row2;
166+ _row_offsets[3 ] = row3;
167+ }
168+
160169/* ********* high level commands, for the user! */
161170void LiquidCrystal::clear ()
162171{
@@ -172,12 +181,15 @@ void LiquidCrystal::home()
172181
173182void LiquidCrystal::setCursor (uint8_t col, uint8_t row)
174183{
175- int row_offsets[] = { 0x00 , 0x40 , 0x14 , 0x54 };
184+ const size_t max_lines = sizeof (_row_offsets) / sizeof (*_row_offsets);
185+ if ( row >= max_lines ) {
186+ row = max_lines - 1 ; // we count rows starting w/0
187+ }
176188 if ( row >= _numlines ) {
177- row = _numlines- 1 ; // we count rows starting w/0
189+ row = _numlines - 1 ; // we count rows starting w/0
178190 }
179191
180- command (LCD_SETDDRAMADDR | (col + row_offsets [row]));
192+ command (LCD_SETDDRAMADDR | (col + _row_offsets [row]));
181193}
182194
183195// Turn the display on/off (quickly)
0 commit comments