LiquidCrystal_PCF8574.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ///
  2. /// \file LiquidCrystal_PCF8574.h
  3. /// \brief LiquidCrystal library with PCF8574 I2C adapter.
  4. ///
  5. /// \author Matthias Hertel, http://www.mathertel.de
  6. ///
  7. /// \copyright Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.
  8. /// \copyright Copyright (c) 2010 Arduino LLC. All right reserved.
  9. /// \copyright Copyright (c) 2014 by Matthias Hertel.\n
  10. ///
  11. /// This library is derived from the original Arduino LiquidCrystal library
  12. /// and uses the original Wire library for communication.
  13. ///
  14. /// From Arduino:
  15. /// This library is free software; you can redistribute it and/or
  16. /// modify it under the terms of the GNU Lesser General Public
  17. /// License as published by the Free Software Foundation; either
  18. /// version 2.1 of the License, or (at your option) any later version.
  19. ///
  20. /// From Author:
  21. /// The extended work is licensed under a BSD style license.\n
  22. /// See http://www.mathertel.de/License.aspx
  23. ///
  24. /// Both License rules apply.
  25. ///
  26. /// \details
  27. /// This is a library for driving LiquidCrystal displays (LCD) by using the I2C bus and an PCF8574 I2C adapter.
  28. /// This library is derived from the original Arduino LiquidCrystal library and uses the original Wire library for communication.
  29. ///
  30. /// ChangeLog:
  31. /// --------
  32. /// * 19.10.2013 created.
  33. /// * 24.05.2015 Arduino Library Manager compatible.
  34. #ifndef LiquidCrystal_PCF8574_h
  35. #define LiquidCrystal_PCF8574_h
  36. #include <inttypes.h>
  37. #include "Print.h"
  38. // commands
  39. #define LCD_CLEARDISPLAY 0x01
  40. #define LCD_RETURNHOME 0x02
  41. #define LCD_ENTRYMODESET 0x04
  42. #define LCD_DISPLAYCONTROL 0x08
  43. #define LCD_CURSORSHIFT 0x10
  44. #define LCD_FUNCTIONSET 0x20
  45. #define LCD_SETCGRAMADDR 0x40
  46. #define LCD_SETDDRAMADDR 0x80
  47. // flags for display entry mode
  48. #define LCD_ENTRYRIGHT 0x00
  49. #define LCD_ENTRYLEFT 0x02
  50. #define LCD_ENTRYSHIFTINCREMENT 0x01
  51. #define LCD_ENTRYSHIFTDECREMENT 0x00
  52. // flags for display on/off control
  53. #define LCD_DISPLAYON 0x04
  54. #define LCD_DISPLAYOFF 0x00
  55. #define LCD_CURSORON 0x02
  56. #define LCD_CURSOROFF 0x00
  57. #define LCD_BLINKON 0x01
  58. #define LCD_BLINKOFF 0x00
  59. // flags for display/cursor shift
  60. #define LCD_DISPLAYMOVE 0x08
  61. #define LCD_CURSORMOVE 0x00
  62. #define LCD_MOVERIGHT 0x04
  63. #define LCD_MOVELEFT 0x00
  64. // flags for function set
  65. #define LCD_8BITMODE 0x10
  66. #define LCD_4BITMODE 0x00
  67. #define LCD_2LINE 0x08
  68. #define LCD_1LINE 0x00
  69. #define LCD_5x10DOTS 0x04
  70. #define LCD_5x8DOTS 0x00
  71. class LiquidCrystal_PCF8574 : public Print {
  72. public:
  73. LiquidCrystal_PCF8574(uint8_t adr);
  74. void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
  75. void clear();
  76. void home();
  77. void noDisplay();
  78. void display();
  79. void noBlink();
  80. void blink();
  81. void noCursor();
  82. void cursor();
  83. void scrollDisplayLeft();
  84. void scrollDisplayRight();
  85. void leftToRight();
  86. void rightToLeft();
  87. void autoscroll();
  88. void noAutoscroll();
  89. void setBacklight(uint8_t brightness);
  90. void createChar(uint8_t, uint8_t[]);
  91. void setCursor(uint8_t col, uint8_t row);
  92. virtual size_t write(uint8_t);
  93. using Print::write;
  94. private:
  95. // low level functions
  96. void _command(uint8_t);
  97. void _send(uint8_t value, uint8_t mode);
  98. void _sendNibble(uint8_t halfByte, uint8_t mode);
  99. void _write2Wire(uint8_t halfByte, uint8_t mode, uint8_t enable);
  100. // NEW:
  101. uint8_t _Addr; ///< Wire Address of the LCD
  102. uint8_t _backlight; ///< the backlight intensity
  103. uint8_t _displayfunction; ///< lines and dots mode
  104. uint8_t _displaycontrol; ///< cursor, display, blink flags
  105. uint8_t _displaymode; ///< left2right, autoscroll
  106. uint8_t _numlines; ///< The number of rows the display supports.
  107. };
  108. #endif