项目作者: pilotak

项目描述 :
LCD & OLED text display library for mbed OS 6
高级语言: C++
项目地址: git://github.com/pilotak/mbed-text-display.git
创建时间: 2021-04-17T21:14:05Z
项目社区:https://github.com/pilotak/mbed-text-display

开源协议:MIT License

下载


Mbed LCD & OLED text display library

Framework Badge mbed

Based on work by sstaub which is based on Simon’s work.
So what is the difference, why another fork?

  • optional R/W pin which enables reading busy flag to avoid fixed waiting time (once the display finishes the task it will let you know)
  • rewritten initialization - not done in constructor in case you are using voltage level translator with OE pin & avoids delays
  • enums are within class context - in case you have a same variable defined elsewhere in the code, it will not collide
  • all display types share the same codebase, they only rewrite pin handling & initialization
  • you can specify char size 5x8 or 5x10 pixels
  • I2C packpack (PCF8574) supported, there are two pinouts on the market - both are supported

Supports HD44780 (tested), RS0010 (tested) and WS0010 (untested) interfaces commonly found in text LCD/OLED displays.

Example

LCD

  1. #include "TextLCD.h"
  2. #define DISPLAY_RS_pin PB_1
  3. #define DISPLAY_E_pin PB_2
  4. #define DISPLAY_D4_pin PB_3
  5. #define DISPLAY_D5_pin PB_4
  6. #define DISPLAY_D6_pin PB_5
  7. #define DISPLAY_D7_pin PB_6
  8. const uint8_t upArrow[8] = {
  9. 0b00100,
  10. 0b01010,
  11. 0b10001,
  12. 0b00100,
  13. 0b00100,
  14. 0b00100,
  15. 0b00000,
  16. };
  17. const uint8_t downArrow[8] = {
  18. 0b00000,
  19. 0b00100,
  20. 0b00100,
  21. 0b00100,
  22. 0b10001,
  23. 0b01010,
  24. 0b00100,
  25. };
  26. const uint8_t rightArrow[8] = {
  27. 0b00000,
  28. 0b00100,
  29. 0b00010,
  30. 0b11001,
  31. 0b00010,
  32. 0b00100,
  33. 0b00000,
  34. };
  35. const uint8_t leftArrow[8] = {
  36. 0b00000,
  37. 0b00100,
  38. 0b01000,
  39. 0b10011,
  40. 0b01000,
  41. 0b00100,
  42. 0b00000,
  43. };
  44. TextLCD lcd(DISPLAY_RS_pin, DISPLAY_E_pin, DISPLAY_D4_pin, DISPLAY_D5_pin,
  45. DISPLAY_D6_pin, DISPLAY_D7_pin);
  46. int main() {
  47. ThisThread::sleep_for(50ms); // give a time to wakeup the controller
  48. lcd.init();
  49. lcd.display(TextLCD::DISPLAY_ON);
  50. lcd.printf("Hello world\n");
  51. // try display functions
  52. ThisThread::sleep_for(2s);
  53. lcd.display(TextLCD::CURSOR_ON);
  54. lcd.display(TextLCD::BLINK_ON);
  55. ThisThread::sleep_for(4s);
  56. lcd.display(TextLCD::BLINK_OFF);
  57. ThisThread::sleep_for(2s);
  58. lcd.display(TextLCD::CURSOR_OFF);
  59. ThisThread::sleep_for(2s);
  60. // clear
  61. lcd.cls();
  62. // create custom characters
  63. lcd.create(0, downArrow);
  64. lcd.create(1, upArrow);
  65. lcd.create(2, rightArrow);
  66. lcd.create(3, leftArrow);
  67. // show custom characters
  68. lcd.locate(0, 0);
  69. lcd.character(0, 0, 0);
  70. lcd.character(2, 0, 1);
  71. lcd.character(4, 0, 2);
  72. lcd.character(6, 0, 3);
  73. // try long text
  74. lcd.locate(0, 0);
  75. lcd.printf("Really long hello world\nwith scrolling");
  76. ThisThread::sleep_for(2s);
  77. // scroll
  78. while (1) {
  79. for (auto pos = 0; pos < (23 - lcd.columns()); pos++) {
  80. lcd.display(TextLCD::SCROLL_LEFT);
  81. ThisThread::sleep_for(150ms);
  82. }
  83. ThisThread::sleep_for(1s);
  84. for (auto pos = 0; pos < (23 - lcd.columns()); pos++) {
  85. lcd.display(TextLCD::SCROLL_RIGHT);
  86. ThisThread::sleep_for(150ms);
  87. }
  88. ThisThread::sleep_for(2s);
  89. }
  90. }

OLED

  1. #include "TextOLED.h"
  2. #define DISPLAY_RS_pin PB_1
  3. #define DISPLAY_E_pin PB_2
  4. #define DISPLAY_D4_pin PB_3
  5. #define DISPLAY_D5_pin PB_4
  6. #define DISPLAY_D6_pin PB_5
  7. #define DISPLAY_D7_pin PB_6
  8. #define DISPLAY_RW_pin PB_7
  9. TextOLED oled(DISPLAY_RS_pin, DISPLAY_E_pin, DISPLAY_D4_pin, DISPLAY_D5_pin,
  10. DISPLAY_D6_pin, DISPLAY_D7_pin, DISPLAY_RW_pin);
  11. const char spinner[] = {0x7C, 0x2F, 0x2D, 0xDA};
  12. int main() {
  13. ThisThread::sleep_for(500ms); // give a time to wakeup the controller
  14. oled.init(TextOLED::FONT_EUROPEAN_I);
  15. oled.display(TextOLED::DISPLAY_ON);
  16. // animate spinner
  17. while(1){
  18. for (size_t i = 0; i < sizeof(spinner); i++) {
  19. oled.character(0, 0, spinner[i]);
  20. ThisThread::sleep_for(150ms);
  21. }
  22. }
  23. }

LCD I2C

  1. #include "TextLCD_I2C.h"
  2. #define SDA PB_9
  3. #define SCL PB_8
  4. TextLCD_I2C lcd(SDA, SCL, false); // set to true if LCD backpack has different pinout
  5. int main() {
  6. ThisThread::sleep_for(50ms); // give a time to wakeup the controller
  7. if (lcd.init()) {
  8. printf("init OK\n");
  9. lcd.display(TextLCD_I2C::DISPLAY_ON);
  10. lcd.setBacklight(true);
  11. lcd.printf("Hello world\n");
  12. } else {
  13. printf("error\n");
  14. }
  15. }

OLED I2C

You can use the constructor same as above or you can pass existing I2C object

  1. #include "TextOLED_I2C.h"
  2. #define SDA PB_9
  3. #define SCL PB_8
  4. I2C i2c(SDA, SCL)
  5. TextOLED_I2C oled;
  6. int main() {
  7. ThisThread::sleep_for(500ms); // give a time to wakeup the controller
  8. if (oled.init(&i2c)) {
  9. printf("init OK\n");
  10. oled.display(TextOLED_I2C::DISPLAY_ON);
  11. oled.printf("Hello world\n");
  12. } else {
  13. printf("error\n");
  14. }
  15. }