Skip to content

Conversation

@netmaniac
Copy link

Hi!
It is my first contribution to Arduino I hope changes I have made are useful ones :)

In case when LiquidCrystal was initialized for 4 line display and using setCursor with line 4 would read some garbage from memory as row_offset

Second change is to allow override behavior of single functions for derived classes. For example - LCD 4x16 has different row_offsets than 4x20 so with all attributes being protected instead of private You can do something like that:

class NewLQ: public LiquidCrystal {
public:
  NewLQ (uint8_t rs, uint8_t e, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) :  LiquidCrystal(rs,e, d0, d1, d2, d3) {
  };
  void setCursor(uint8_t col, uint8_t row)
  {
    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]));
  };
};

and then use NewLQ if You have 4x16 instead of copying whole LiquidCrystal into sketch and making changes to row offsets.

Row offsets I got from this thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253367247

I'll try to patch LiquidCrystal to work out of the box both with 4x20 and 4x16, but this is simple fix useful in more scenarios.

@matthijskooijman
Copy link
Collaborator

The first patch from this request is better fixed by #55, IMHO.
The second patch is already included in the codebase, so I think this this request can be closed.

@ffissore ffissore added the New label Feb 27, 2014
@cmaglie cmaglie added feature request A request to make an enhancement (not a bug fix) and removed New labels Sep 7, 2014
@cmaglie cmaglie closed this Nov 7, 2014
tbowmo pushed a commit to tbowmo/Arduino that referenced this pull request Jul 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request A request to make an enhancement (not a bug fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants