Skip to content

Commit 659d36b

Browse files
committed
Compile error in example CustomChars, used print(x, BYTE) that is not deprecated in Arduino 1.0.
Refactored the initialization of the library, unneeded init functions are removed. Removed double member field _numlines (already has _rows).
1 parent 06c09fe commit 659d36b

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

LiquidCrystal_I2C.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,25 @@
2222
// can't assume that its in that state when a sketch starts (and the
2323
// LiquidCrystal constructor is called).
2424

25-
LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_addr,uint8_t lcd_cols,uint8_t lcd_rows)
25+
LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t lcd_addr, uint8_t lcd_cols, uint8_t lcd_rows, uint8_t dotsize)
2626
{
2727
_addr = lcd_addr;
2828
_cols = lcd_cols;
2929
_rows = lcd_rows;
30+
_dotsize = dotsize;
3031
_backlightval = LCD_NOBACKLIGHT;
3132
}
3233

33-
void LiquidCrystal_I2C::init(){
34-
init_priv();
35-
}
36-
37-
void LiquidCrystal_I2C::init_priv()
38-
{
34+
void LiquidCrystal_I2C::begin() {
3935
Wire.begin();
4036
_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS;
41-
begin(_cols, _rows);
42-
}
4337

44-
void LiquidCrystal_I2C::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) {
45-
if (lines > 1) {
38+
if (_rows > 1) {
4639
_displayfunction |= LCD_2LINE;
4740
}
48-
_numlines = lines;
4941

5042
// for some 1 line displays you can select a 10 pixel high font
51-
if ((dotsize != 0) && (lines == 1)) {
43+
if ((_dotsize != 0) && (_rows == 1)) {
5244
_displayfunction |= LCD_5x10DOTS;
5345
}
5446

@@ -112,8 +104,8 @@ void LiquidCrystal_I2C::home(){
112104

113105
void LiquidCrystal_I2C::setCursor(uint8_t col, uint8_t row){
114106
int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };
115-
if (row > _numlines) {
116-
row = _numlines-1; // we count rows starting w/0
107+
if (row > _rows) {
108+
row = _rows-1; // we count rows starting w/0
117109
}
118110
command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
119111
}

LiquidCrystal_I2C.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353

5454
class LiquidCrystal_I2C : public Print {
5555
public:
56-
LiquidCrystal_I2C(uint8_t lcd_addr,uint8_t lcd_cols,uint8_t lcd_rows);
57-
void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
56+
LiquidCrystal_I2C(uint8_t lcd_addr,uint8_t lcd_cols,uint8_t lcd_rows, uint8_t charsize = LCD_5x8DOTS);
57+
void begin();
5858
void clear();
5959
void home();
6060
void noDisplay();
@@ -79,7 +79,6 @@ class LiquidCrystal_I2C : public Print {
7979
void setCursor(uint8_t, uint8_t);
8080
virtual size_t write(uint8_t);
8181
void command(uint8_t);
82-
void init();
8382

8483
inline void blink_on() { blink(); }
8584
inline void blink_off() { noBlink(); }
@@ -103,7 +102,6 @@ class LiquidCrystal_I2C : public Print {
103102
void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end);
104103

105104
private:
106-
void init_priv();
107105
void send(uint8_t, uint8_t);
108106
void write4bits(uint8_t);
109107
void expanderWrite(uint8_t);
@@ -112,9 +110,9 @@ class LiquidCrystal_I2C : public Print {
112110
uint8_t _displayfunction;
113111
uint8_t _displaycontrol;
114112
uint8_t _displaymode;
115-
uint8_t _numlines;
116113
uint8_t _cols;
117114
uint8_t _rows;
115+
uint8_t _dotsize;
118116
uint8_t _backlightval;
119117
};
120118

examples/CustomChars/CustomChars.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LiquidCrystal_I2C lcd(0x27, 16, 2);
1515

1616
void setup()
1717
{
18-
lcd.init();
18+
lcd.begin();
1919
lcd.backlight();
2020

2121
lcd.createChar(0, bell);
@@ -31,7 +31,7 @@ void setup()
3131
lcd.print("Hello world...");
3232
lcd.setCursor(0, 1);
3333
lcd.print(" i ");
34-
lcd.print(3, BYTE);
34+
lcd.write(3);
3535
lcd.print(" arduinos!");
3636
delay(5000);
3737
displayKeyCodes();
@@ -50,7 +50,7 @@ void displayKeyCodes(void) {
5050
lcd.setCursor(0, 1);
5151

5252
for (int j = 0; j < 16; j++) {
53-
lcd.print(i + j, BYTE);
53+
lcd.write(i + j);
5454
}
5555
i += 16;
5656

examples/HelloWorld/HelloWorld.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LiquidCrystal_I2C lcd(0x27, 16, 2);
77
void setup()
88
{
99
// initialize the LCD
10-
lcd.init();
10+
lcd.begin();
1111

1212
// Turn on the blacklight and print a message.
1313
lcd.backlight();

examples/SerialDisplay/SerialDisplay.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LiquidCrystal_I2C lcd(0x27, 16, 2);
1010

1111
void setup()
1212
{
13-
lcd.init();
13+
lcd.begin();
1414
lcd.backlight();
1515

1616
// Initialize the serial port at a speed of 9600 baud

0 commit comments

Comments
 (0)