Update LCD display on I2C. Specify Columns and up to 4 Rows. Init pin can be used to prevent extra clear displays. Passing null string for a Line will leave the line untouched.
lcd-i2c-init
@/lcd-i2c-init
Update LCD display on I2C. Specify Columns and up to 4 Rows. Init pin can be used to prevent extra clear displays. Passing null string for a Line will leave the line untouched.
Initboolean
Initialize LCD. Must be done at least once, but also clears screen. If you have multiple nodes for same LCD & each displays on a different line, Init false prevents clearing display and losing other lines.
ADDRnumber
I²C address of the expander chip.
ROWSnumber
Number of Rows on LCD display. L pins greater than this will be ignored.
COLSnumber
Number of columns on LCD display. Output for each line will be truncated at this length.
BLboolean
Backlight enable/disable
L1string
Text for the first line. A null string will leave line untouched. A single space (or other short string) will clear to end-of-line. Lines > ROWS will be ignored
L2string
Text for the second line
L3string
Text for the third line
L4string
Text for the forth line
To use the node in your project you should have the gweimer/lcd-i2c-init library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
{{#global}}
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
{{/global}}
struct State {
LiquidCrystal_I2C* lcd;
};
{{ GENERATED_CODE }}
void printLine(LiquidCrystal_I2C* lcd, uint8_t cols, uint8_t rows, uint8_t lineIndex, XString str) {
if (lineIndex >= rows)
return;
lcd->setCursor(0, lineIndex);
uint8_t whitespace = cols;
for (auto it = str.iterate(); it && whitespace; ++it, --whitespace)
lcd->write(*it);
// Clear the rest of the line
if (whitespace < cols) {
while (whitespace--)
lcd->write(' ');
}
}
void evaluate(Context ctx) {
State* state = getState(ctx);
auto lcd = state->lcd;
auto rows = getValue<input_ROWS>(ctx);
auto cols = getValue<input_COLS>(ctx);
if (!state->lcd) {
uint8_t addr = getValue<input_ADDR>(ctx);
state->lcd = lcd = new LiquidCrystal_I2C(addr, cols, rows);
if (getValue<input_Init>(ctx))
lcd->begin();
}
printLine(lcd, cols, rows, 0, getValue<input_L1>(ctx));
printLine(lcd, cols, rows, 1, getValue<input_L2>(ctx));
printLine(lcd, cols, rows, 2, getValue<input_L3>(ctx));
printLine(lcd, cols, rows, 3, getValue<input_L4>(ctx));
lcd->setBacklight(getValue<input_BL>(ctx));
}