From bd498e98b9d79d75e1383faf56fccbc6dd9efcd2 Mon Sep 17 00:00:00 2001 From: Axel Date: Thu, 31 Oct 2019 03:10:54 -0300 Subject: [PATCH] Compatibility row offset for 16 and 20 columns LCD --- LiquidTWI2.cpp | 18 ++++++++++++++++-- LiquidTWI2.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/LiquidTWI2.cpp b/LiquidTWI2.cpp index 312d455..76652c2 100644 --- a/LiquidTWI2.cpp +++ b/LiquidTWI2.cpp @@ -117,6 +117,21 @@ void LiquidTWI2::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { Wire.begin(); uint8_t result; + + if (cols == 20 && lines == 4 ) { + _row_offsets [0] = 0x00; + _row_offsets [1] = 0x40; + _row_offsets [2] = 0x14; + _row_offsets [3] = 0x54; + } else{ + _row_offsets [0] = 0x00; + _row_offsets [1] = 0x40; + _row_offsets [2] = 0x10; + _row_offsets [3] = 0x50; + } + + + #if defined(MCP23017)&&defined(MCP23008) if (_mcpType == LTI_TYPE_MCP23017) { #endif @@ -344,9 +359,8 @@ void LiquidTWI2::setCursor(uint8_t col, uint8_t row) #ifdef DETECT_DEVICE if (!_deviceDetected) return; #endif - int row_offsets[] = { 0x00, 0x40, 0x10, 0x50 }; if ( row > _numlines ) 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/LiquidTWI2.h b/LiquidTWI2.h index 2cdb2c2..3a05518 100644 --- a/LiquidTWI2.h +++ b/LiquidTWI2.h @@ -196,6 +196,7 @@ class LiquidTWI2 : public Print { uint8_t _numlines,_currline; uint8_t _i2cAddr; uint8_t _backlightInverted; + uint16_t _row_offsets[4]; #ifdef DETECT_DEVICE uint8_t _deviceDetected; #endif // DETECT_DEVICE