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

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