From 03a6b2c54a2547e9012376a3c2e1d8cb090b081b Mon Sep 17 00:00:00 2001 From: Mark Sproul Date: Sun, 4 Dec 2011 16:54:32 -0500 Subject: [PATCH] Added setRowOffsets to LiquidCrystal library Original commit by Mark Sproul, but cleaned up by Matthijs Kooijman. --- libraries/LiquidCrystal/src/LiquidCrystal.cpp | 15 ++++++++++++--- libraries/LiquidCrystal/src/LiquidCrystal.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/LiquidCrystal/src/LiquidCrystal.cpp b/libraries/LiquidCrystal/src/LiquidCrystal.cpp index 0653487d7..5dbb830f9 100644 --- a/libraries/LiquidCrystal/src/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/src/LiquidCrystal.cpp @@ -79,6 +79,8 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; + setRowOffsets(0x00, 0x40, 0x14, 0x54); + begin(16, 1); } @@ -157,6 +159,14 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { } +void LiquidCrystal::setRowOffsets(int row0, int row1, int row2, int row3) +{ + _row_offsets[0] = row0; + _row_offsets[1] = row1; + _row_offsets[2] = row2; + _row_offsets[3] = row3; +} + /********** high level commands, for the user! */ void LiquidCrystal::clear() { @@ -172,12 +182,11 @@ void LiquidCrystal::home() 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 + row = _numlines - 1; // we count rows starting w/0 } - command(LCD_SETDDRAMADDR | (col + row_offsets[row])); + command(LCD_SETDDRAMADDR | (col + _row_offsets[row])); } // Turn the display on/off (quickly) diff --git a/libraries/LiquidCrystal/src/LiquidCrystal.h b/libraries/LiquidCrystal/src/LiquidCrystal.h index 24ec5afdf..1c0fa4fb0 100644 --- a/libraries/LiquidCrystal/src/LiquidCrystal.h +++ b/libraries/LiquidCrystal/src/LiquidCrystal.h @@ -77,6 +77,7 @@ public: void autoscroll(); void noAutoscroll(); + void setRowOffsets(int row1, int row2, int row3, int row4); void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t, uint8_t); virtual size_t write(uint8_t); @@ -101,6 +102,7 @@ private: uint8_t _initialized; uint8_t _numlines,_currline; + int _row_offsets[4]; }; #endif