LiquidCrystal_I2C.h 3.4 KB

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