DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SerialLCD.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // see https://github.com/sparkfun/SparkFun_SerLCD_Arduino_Library
  2. #include <Arduino.h>
  3. #include "SerialLCD.h"
  4. #ifdef FUNCTION_UI
  5. #define LCD_DELAY 3 // 3
  6. SerialLCD::SerialLCD(int tx_pin) {
  7. #if defined(PLATFORM_AVR)
  8. lcd = new SendOnlySoftwareSerial(tx_pin);
  9. #elif defined(PLATFORM_ESP)
  10. lcd = new SoftwareSerial(tx_pin);
  11. #endif
  12. lcd->begin(9600);
  13. }
  14. SerialLCD::~SerialLCD(void) {
  15. delete lcd;
  16. }
  17. void SerialLCD::init(void) {
  18. clear();
  19. cursor(0);
  20. setBacklight(255);
  21. lcd->write(0x7C);
  22. lcd->write(0x03); // 0x03=20 chars. 0x04=16 chars
  23. delay(LCD_DELAY);
  24. lcd->write(0x7C);
  25. lcd->write(0x05); // 0x05=4 lines, 0x06=2 lines
  26. delay(LCD_DELAY);
  27. }
  28. void SerialLCD::clear(void) {
  29. lcd->write(0xFE);
  30. lcd->write(0x01);
  31. delay(LCD_DELAY);
  32. }
  33. // 0 no cursor, 1 underline, 2 blinking, 3 both
  34. void SerialLCD::cursor(int style) {
  35. lcd->write(0xFE);
  36. lcd->write(0x0C); // display on, no cursor
  37. delay(LCD_DELAY);
  38. if (style == 1) {
  39. lcd->write(0xFE);
  40. lcd->write(0x0E); // underline cursor on
  41. delay(LCD_DELAY);
  42. } else if (style == 2) {
  43. lcd->write(0xFE);
  44. lcd->write(0x0D); // blinking cursor on
  45. delay(LCD_DELAY);
  46. } else if (style == 3) {
  47. lcd->write(0xFE);
  48. lcd->write(0x0F); // both cursors on
  49. delay(LCD_DELAY);
  50. }
  51. }
  52. void SerialLCD::setBacklight(uint8_t val) {
  53. val = map(val, 0, 255, 0, 30);
  54. lcd->write(0x7C);
  55. lcd->write(0x80 + val);
  56. delay(LCD_DELAY);
  57. }
  58. void SerialLCD::position(int line, int col) {
  59. int cursor = 0;
  60. if (line == 1) {
  61. cursor = 64;
  62. } else if (line == 2) {
  63. cursor = 20;
  64. } else if (line == 3) {
  65. cursor = 84;
  66. }
  67. lcd->write(0xFE);
  68. lcd->write(0x80 + cursor + col);
  69. delay(LCD_DELAY);
  70. }
  71. void SerialLCD::saveSplash(void) {
  72. lcd->write(0x7C);
  73. lcd->write(0x0A);
  74. }
  75. void SerialLCD::enableSplash(void) {
  76. lcd->write(0x7C);
  77. lcd->write(0x30);
  78. }
  79. void SerialLCD::disableSplash(void) {
  80. lcd->write(0x7C);
  81. lcd->write(0x31);
  82. }
  83. void SerialLCD::write(const char *text) {
  84. lcd->print(text);
  85. delay(LCD_DELAY);
  86. }
  87. void SerialLCD::write(int line, const char *text) {
  88. position(line, 0);
  89. write(text);
  90. }
  91. void SerialLCD::write(int line, int col, const char *text) {
  92. position(line, col);
  93. write(text);
  94. }
  95. #endif // FUNCTION_UI