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 1.9KB

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