LCD
#Description
An LCD is a simple display that can display up to 32 characters and change its background colour. Perfect for showing simple states or messages.
#Links
#Aliases
- LCD Display
#Functions
#JavaScript / Node.js
LCDextends I2cComponentBaseLCD component for controlling a 16x2 I2C character display with RGB backlight (Grove LCD RGB Backlight). Extends ComponentBase as a complex output component with custom serial commands.
#Value type
interface LCDValue {
string: string;
backgroundColor: string;
}#Constructor options
| Option | Type | Required | Description | Inherited from |
|---|---|---|---|---|
pin | I2CPinID | required | — | I2cComponentBase |
#Events
| Event | Parameters | Description |
|---|---|---|
change | value: LCDValue | — |
#Methods
drawString(text: string)Draw text on the display using the shadow-diff streaming protocol. Only changed character cells are rewritten, avoiding flicker. Long text is automatically chunked by the serial protocol layer.
print(text: string)@deprecated Use drawString() instead. Kept for backwards compatibility.
clear()Clear the display.
setCursor(col: number, row: number)Set the cursor position.
setRGB(r: number, g: number, b: number)Set backlight color using RGB values.
bgColor(hex: string)Set backlight color using a hex string.
backlightOff()Turn off the backlight.
get i2cId→ I2CPinIDfrom I2cComponentBaseThe resolved I2C pin ID (e.g. "i2c-0"). Useful for logging or passing back to the Arduino sketch.
#Example
import { Board, LCD } from "@blokdots/components";
const board = new Board("/dev/ttyACM0");
await board.open();
const lCD = new LCD({ board, pin: "example" });#C++ (Arduino)
16x2 I2C LCD with RGB backlight using Seeed's Grove_LCD_RGB_Backlight library. - Uses ComponentBase begin()/tick() registration. - Optional EventBus "changed" event emission (rate-limited).
#Required libraries
#include <Wire.h>— Wire#include <rgb_lcd.h>— Grove - LCD RGB Backlight v1.0.2
#Setup
#include "blokdots.h"
LCDDisplay myComponent();#Constructor
LCDDisplay(cols, rows, charSize, wire, startR, startG, startB, startBacklightOn)| Parameter | Type | Default |
|---|---|---|
cols | uint8_t | 16 |
rows | uint8_t | 2 |
charSize | uint8_t | LCD_5x8DOTS |
wire | TwoWire | Wire |
startR | uint8_t | 255 |
startG | uint8_t | 255 |
startB | uint8_t | 255 |
startBacklightOn | bool | true |
LCDDisplay(bus, evtChanged, cols, rows, charSize, wire, startR, startG, startB, startBacklightOn, minEmitIntervalMs)| Parameter | Type | Default |
|---|---|---|
bus | EventBus | required |
evtChanged | uint8_t | required |
cols | uint8_t | 16 |
rows | uint8_t | 2 |
charSize | uint8_t | LCD_5x8DOTS |
wire | TwoWire | Wire |
startR | uint8_t | 255 |
startG | uint8_t | 255 |
startB | uint8_t | 255 |
startBacklightOn | bool | true |
minEmitIntervalMs | uint16_t | 0 |
#Methods
clear()home()setCursor(col, row)| Parameter | Type | Default |
|---|---|---|
col | uint8_t | required |
row | uint8_t | required |
print(s)Print helpers — all route through drawString() for shadow-diff / no-flicker.
| Parameter | Type | Default |
|---|---|---|
s | const char | required |
print(v)| Parameter | Type | Default |
|---|---|---|
v | int | required |
print(v)| Parameter | Type | Default |
|---|---|---|
v | unsigned int | required |
print(v)| Parameter | Type | Default |
|---|---|---|
v | long | required |
print(v)| Parameter | Type | Default |
|---|---|---|
v | unsigned long | required |
print(v, digits)| Parameter | Type | Default |
|---|---|---|
v | float | required |
digits | uint8_t | 2 |
setRGB(r, g, b)| Parameter | Type | Default |
|---|---|---|
r | uint8_t | required |
g | uint8_t | required |
b | uint8_t | required |
bgColor(r, g, b)alias (kept for compatibility)
| Parameter | Type | Default |
|---|---|---|
r | uint8_t | required |
g | uint8_t | required |
b | uint8_t | required |
bgColor(hex)Optional: hex input, uses your color utils
| Parameter | Type | Default |
|---|---|---|
hex | const char | required |
backlightOff()isBacklightOn()→ boolsetLine(row, text)| Parameter | Type | Default |
|---|---|---|
row | uint8_t | required |
text | const char | required |
setText2(line0, line1)| Parameter | Type | Default |
|---|---|---|
line0 | const char | required |
line1 | const char | required |
drawString(text)Uses the same shadow-diff logic: only changed cells are written.
| Parameter | Type | Default |
|---|---|---|
text | const char | required |
beginDrawString()drawStringChunk(text)| Parameter | Type | Default |
|---|---|---|
text | const char | required |
endDrawString()displayOn()displayOff()cursorOn()cursorOff()blinkOn()blinkOff()blinkLEDOn()blinkLEDOff()autoscrollOn()autoscrollOff()leftToRight()rightToLeft()scrollDisplayLeft()scrollDisplayRight()createChar(location, charmap[])| Parameter | Type | Default |
|---|---|---|
location | uint8_t | required |
charmap[] | uint8_t | required |
columns()→ uint8_trowsCount()→ uint8_t