From f82ec65a0d6e22f39266e91b85cb615df0780b3f Mon Sep 17 00:00:00 2001 From: Manfred Jonsson Date: Mon, 28 May 2012 15:38:41 +0200 Subject: [PATCH] Fixes --- libraries/LiquidCrystal/LiquidCrystal.cpp | 28 +++++++++---------- libraries/LiquidCrystal/LiquidCrystal.h | 9 +++--- .../CustomCharacter/CustomCharacter.ino | 5 ++-- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/libraries/LiquidCrystal/LiquidCrystal.cpp b/libraries/LiquidCrystal/LiquidCrystal.cpp index 0653487d70..771293f352 100644 --- a/libraries/LiquidCrystal/LiquidCrystal.cpp +++ b/libraries/LiquidCrystal/LiquidCrystal.cpp @@ -78,19 +78,17 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; - - begin(16, 1); } -void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { - if (lines > 1) { +void LiquidCrystal::begin(uint8_t cols, uint8_t rows, uint8_t dotsize) { + if (rows > 1) { _displayfunction |= LCD_2LINE; } - _numlines = lines; - _currline = 0; + _numcols = cols; + _numrows = rows; // for some 1 line displays you can select a 10 pixel high font - if ((dotsize != 0) && (lines == 1)) { + if ((dotsize != 0) && (rows == 1)) { _displayfunction |= LCD_5x10DOTS; } @@ -151,7 +149,7 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { clear(); // Initialize to default text direction (for romance languages) - _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; + _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDISABLE; // set the entry mode command(LCD_ENTRYMODESET | _displaymode); @@ -172,9 +170,9 @@ 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 + int row_offsets[] = { 0x00, 0x40, _numcols, 0x40 + _numcols }; + if ( row >= _numrows ) { + row = _numrows - 1; // we count rows starting w/0 } command(LCD_SETDDRAMADDR | (col + row_offsets[row])); @@ -230,15 +228,15 @@ void LiquidCrystal::rightToLeft(void) { command(LCD_ENTRYMODESET | _displaymode); } -// This will 'right justify' text from the cursor +// This will move the text on write, looks like a fixed cursor void LiquidCrystal::autoscroll(void) { - _displaymode |= LCD_ENTRYSHIFTINCREMENT; + _displaymode |= LCD_ENTRYSHIFTENABLE; command(LCD_ENTRYMODESET | _displaymode); } -// This will 'left justify' text from the cursor +// This will fix the text and moves the cursor on write void LiquidCrystal::noAutoscroll(void) { - _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; + _displaymode &= ~LCD_ENTRYSHIFTENABLE; command(LCD_ENTRYMODESET | _displaymode); } diff --git a/libraries/LiquidCrystal/LiquidCrystal.h b/libraries/LiquidCrystal/LiquidCrystal.h index 24ec5afdf5..3d044bb6d2 100755 --- a/libraries/LiquidCrystal/LiquidCrystal.h +++ b/libraries/LiquidCrystal/LiquidCrystal.h @@ -17,8 +17,8 @@ // flags for display entry mode #define LCD_ENTRYRIGHT 0x00 #define LCD_ENTRYLEFT 0x02 -#define LCD_ENTRYSHIFTINCREMENT 0x01 -#define LCD_ENTRYSHIFTDECREMENT 0x00 +#define LCD_ENTRYSHIFTENABLE 0x01 +#define LCD_ENTRYSHIFTDISABLE 0x00 // flags for display on/off control #define LCD_DISPLAYON 0x04 @@ -98,9 +98,8 @@ class LiquidCrystal : public Print { uint8_t _displaycontrol; uint8_t _displaymode; - uint8_t _initialized; - - uint8_t _numlines,_currline; + uint8_t _numcols; + uint8_t _numrows; }; #endif diff --git a/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino index d3ce479246..a320694b5c 100644 --- a/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino +++ b/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino @@ -97,6 +97,9 @@ byte armsUp[8] = { 0b01010 }; void setup() { + // set up the lcd's number of columns and rows: + lcd.begin(16, 2); + // create a new character lcd.createChar(0, heart); // create a new character @@ -108,8 +111,6 @@ void setup() { // create a new character lcd.createChar(4, armsUp); - // set up the lcd's number of columns and rows: - lcd.begin(16, 2); // Print a message to the lcd. lcd.print("I "); lcd.write(0);