LiquidCrystal_I2C.h


1
// LiquidCrystal_I2C V2.0
2
3
#ifndef LiquidCrystal_I2C_h
4
#define LiquidCrystal_I2C_h
5
6
#include <inttypes.h>
7
#include "Print.h" 
8
#include <Wire.h>
9
10
// commands
11
#define LCD_CLEARDISPLAY 0x01
12
#define LCD_RETURNHOME 0x02
13
#define LCD_ENTRYMODESET 0x04
14
#define LCD_DISPLAYCONTROL 0x08
15
#define LCD_CURSORSHIFT 0x10
16
#define LCD_FUNCTIONSET 0x20
17
#define LCD_SETCGRAMADDR 0x40
18
#define LCD_SETDDRAMADDR 0x80
19
20
// flags for display entry mode
21
#define LCD_ENTRYRIGHT 0x00
22
#define LCD_ENTRYLEFT 0x02
23
#define LCD_ENTRYSHIFTINCREMENT 0x01
24
#define LCD_ENTRYSHIFTDECREMENT 0x00
25
26
// flags for display on/off control
27
#define LCD_DISPLAYON 0x04
28
#define LCD_DISPLAYOFF 0x00
29
#define LCD_CURSORON 0x02
30
#define LCD_CURSOROFF 0x00
31
#define LCD_BLINKON 0x01
32
#define LCD_BLINKOFF 0x00
33
34
// flags for display/cursor shift
35
#define LCD_DISPLAYMOVE 0x08
36
#define LCD_CURSORMOVE 0x00
37
#define LCD_MOVERIGHT 0x04
38
#define LCD_MOVELEFT 0x00
39
40
// flags for function set
41
#define LCD_8BITMODE 0x10
42
#define LCD_4BITMODE 0x00
43
#define LCD_2LINE 0x08
44
#define LCD_1LINE 0x00
45
#define LCD_5x10DOTS 0x04
46
#define LCD_5x8DOTS 0x00
47
48
// flags for backlight control
49
#define LCD_BACKLIGHT 0x00
50
#define LCD_NOBACKLIGHT 0x80
51
52
#define En B00010000  // Enable bit
53
#define Rw B00100000  // Read/Write bit
54
#define Rs B01000000  // Register select bit
55
56
class LiquidCrystal_I2C : public Print {
57
public:
58
  LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows);
59
  void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
60
  void clear();
61
  void home();
62
  void noDisplay();
63
  void display();
64
  void noBlink();
65
  void blink();
66
  void noCursor();
67
  void cursor();
68
  void scrollDisplayLeft();
69
  void scrollDisplayRight();
70
  void printLeft();
71
  void printRight();
72
  void leftToRight();
73
  void rightToLeft();
74
  void shiftIncrement();
75
  void shiftDecrement();
76
  void noBacklight();
77
  void backlight();
78
  void autoscroll();
79
  void noAutoscroll(); 
80
  void createChar(uint8_t, uint8_t[]);
81
  void setCursor(uint8_t, uint8_t); 
82
  virtual size_t write(uint8_t);
83
  void command(uint8_t);
84
  void init();
85
86
////compatibility API function aliases
87
void blink_on();            // alias for blink()
88
void blink_off();                 // alias for noBlink()
89
void cursor_on();                   // alias for cursor()
90
void cursor_off();                // alias for noCursor()
91
void setBacklight(uint8_t new_val);        // alias for backlight() and nobacklight()
92
void load_custom_character(uint8_t char_num, uint8_t *rows);  // alias for createChar()
93
void printstr(const char[]);
94
95
////Unsupported API functions (not implemented in this library)
96
uint8_t status();
97
void setContrast(uint8_t new_val);
98
uint8_t keypad();
99
void setDelay(int,int);
100
void on();
101
void off();
102
uint8_t init_bargraph(uint8_t graphtype);
103
void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_col_end);
104
void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len,  uint8_t pixel_col_end);
105
   
106
107
private:
108
  void init_priv();
109
  void send(uint8_t, uint8_t);
110
  void write4bits(uint8_t);
111
  void expanderWrite(uint8_t);
112
  void pulseEnable(uint8_t);
113
  uint8_t _Addr;
114
  uint8_t _displayfunction;
115
  uint8_t _displaycontrol;
116
  uint8_t _displaymode;
117
  uint8_t _numlines;
118
  uint8_t _cols;
119
  uint8_t _rows;
120
  uint8_t _backlightval;
121
};
122
123
#endif