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.0KB

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