1
+ /* !
2
+ * @file drvOutCharLcd.h
3
+ *
4
+ * Device driver for I2C Character LCDs (HD44780)
5
+ *
6
+ * Adafruit invests time and resources providing this open source code,
7
+ * please support Adafruit and open-source hardware by purchasing
8
+ * products from Adafruit!
9
+ *
10
+ * Copyright (c) Brent Rubell for Adafruit Industries 2025
11
+ *
12
+ * MIT license, all text here must be included in any redistribution.
13
+ *
14
+ */
15
+
16
+ #ifndef DRV_OUT_CHAR_LCD
17
+ #define DRV_OUT_CHAR_LCD
18
+
19
+ #include " drvOutputBase.h"
20
+ #include < Adafruit_LiquidCrystal.h>
21
+ #include < Arduino.h>
22
+
23
+ /* !
24
+ @brief Class that provides a driver interface for a lcd character display.
25
+ This class is a wrapper around the Adafruit_LiquidCrystal library.
26
+ */
27
+ class drvOutCharLcd : public drvOutputBase {
28
+ public:
29
+ /* !
30
+ @brief Constructor for a lcd character display.
31
+ @param i2c
32
+ The I2C interface.
33
+ @param sensorAddress
34
+ 7-bit device address.
35
+ @param mux_channel
36
+ The I2C multiplexer channel.
37
+ @param driver_name
38
+ The name of the driver.
39
+ */
40
+ drvOutCharLcd (TwoWire *i2c, uint16_t sensorAddress, uint32_t mux_channel,
41
+ const char *driver_name)
42
+ : drvOutputBase(i2c, sensorAddress, mux_channel, driver_name) {
43
+ // Initialization handled by drvOutPutBase constructor
44
+ }
45
+
46
+ /* !
47
+ @brief Destructor for a quad alphanumeric display.
48
+ */
49
+ ~drvOutCharLcd () {
50
+ if (_lcd) {
51
+ delete _lcd;
52
+ _lcd = nullptr ;
53
+ }
54
+ }
55
+
56
+ /* !
57
+ @brief Initializes an I2C character LCD and begins I2C communication.
58
+ @returns True if initialized successfully, False otherwise.
59
+ */
60
+ bool begin () override {
61
+ _lcd = new Adafruit_LiquidCrystal (_address, _i2c);
62
+ bool did_begin = _lcd->begin (_cols, _rows);
63
+ if (did_begin && _enable_backlight) {
64
+ _lcd->setBacklight (LOW);
65
+ }
66
+ return did_begin;
67
+ }
68
+
69
+ /* !
70
+ @brief Writes a message to the LCD.
71
+ @note MUST be called prior to begin() to configure the LCD's size
72
+ @param message
73
+ The message to be displayed.
74
+ */
75
+ void ConfigureCharLcd (uint8_t rows, uint8_t cols, bool enable_backlight) {
76
+ _rows = rows;
77
+ _cols = cols;
78
+ _enable_backlight = enable_backlight;
79
+ }
80
+
81
+ protected:
82
+ Adafruit_LiquidCrystal
83
+ *_lcd; // /< Pointer to the Adafruit_LiquidCrystal object
84
+ uint8_t _rows = 2 ; // /< Number of rows in the display
85
+ uint8_t _cols = 16 ; // /< Number of columns in the display
86
+ bool _enable_backlight; // /< Flag to enable/disable backlight
87
+ };
88
+
89
+ #endif // DRV_OUT_CHAR_LCD
0 commit comments