Update LCD display on I2C. Specify Columns and up to 4 Rows. Init pin can be used to prevent extra clear displays. Null string for a Line will leave the line untouched; space will clear the line.
lcd-i2c-init-v
@/lcd-i2c-init-v
Update LCD display on I2C. Specify Columns and up to 4 Rows. Init pin can be used to prevent extra clear displays. Null string for a Line will leave the line untouched; space will clear the line.
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. MUST equal # variadic pins for L.
COLSnumber
Number of columns on LCD display. Output for each line will be truncated at this length.
BLboolean
Backlight enable/disable
INnumber
Lstring (variadic)
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
OUTnumber
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);
auto row = getValue<input_IN>(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) && row == 0)
lcd->begin();
}
printLine(lcd, cols, rows, row, getValue<input_L>(ctx));
lcd->setBacklight(getValue<input_BL>(ctx));
//emitValue<output_OUT1>(ctx, false);
emitValue<output_OUT>(ctx, row + 1);
}