Abdellazizhammami / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Enhance LCD methods 'scrollDisplayLeft' and 'scrollDisplayRight' to accept a parameter #726

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What change would like to see?
Currently 'scrollDisplayLeft' and 'scrollDisplayRight' do not accept 
parameters.  I would to to proved an integer to indicate a scroll amount other 
than the default of '1'.

Why?
To simplify project code and make the function more versatile.
Seldom is it needed to shift the display only one positions.  Therefore, it is 
necessary to put the function in a loop.  This complicates the codes.
If I need to scroll my display 16 positions (a common display width) I 
currently need to write something like:
   for (uint8_t i=16; i--;) scrollDisplayLeft();
This is the most compact and efficient code I have been able to come up with.
A more efficient method would be:
   scrollDisplayLeft(16);

The compiler could better optimize the code since there is only one loop in one 
location rather than several loops in different locations.

Would this cause any incompatibilities with previous versions?
No.

This is my tested proposed code based on arduino-1.0-rc2:
LiquidCrystal.h
  void scrollDisplayLeft(uint8_t iCnt=1);
  void scrollDisplayRight(uint8_t iCnt=1);

LiquidCrystal.c
void LiquidCrystal::scrollDisplayLeft(uint8_t iCnt) {
  while (iCnt-- != 0)
    command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT);
}
void LiquidCrystal::scrollDisplayRight(uint8_t iCnt) {
  while (iCnt-- != 0)
    command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT);
}

Original issue reported on code.google.com by Randall....@gmail.com on 22 Nov 2011 at 4:22