Elcdx (elcdx v0.1.1)
View SourceElixir library for communicating with ELCD LCD display modules via UART.
This library provides a simple and efficient way to control LCD displays through UART communication. It supports various LCD operations including:
- Text display with automatic line wrapping
- Cursor control (show/hide)
- Screen clearing and positioning
- Scrolling text functionality
- Multiple display sizes support
Example
{:ok, lcd} = Elcdx.start_link("/dev/ttyUSB0")
Elcdx.clear(lcd)
Elcdx.print(lcd, "Hello, World!")
Elcdx.move(lcd, 0, 1)
Elcdx.print(lcd, "Line 2 text")Configuration
The library supports various LCD configurations:
- 16x2 (default)
- 20x4
- Custom sizes
Default UART settings:
- Baud rate: 19200
- Data bits: 8
- Stop bits: 1
- Parity: None
Summary
Functions
Clears the LCD display.
Hides the cursor.
Shows the cursor.
Moves the cursor to the specified position.
Displays text on the LCD.
Starts a new LCD connection.
Stops the LCD connection and cleans up resources.
Types
@type start_option() :: {:device, String.t()} | {:speed, pos_integer()} | {:lines, pos_integer()} | {:columns, pos_integer()}
@type t() :: Elcdx.Driver.t()
Functions
Clears the LCD display.
Example
Elcdx.clear(lcd)
Hides the cursor.
Example
Elcdx.cursor_off(lcd)
Shows the cursor.
Example
Elcdx.cursor_on(lcd)
@spec move(t(), non_neg_integer(), non_neg_integer()) :: :ok | {:error, term()}
Moves the cursor to the specified position.
Parameters
lcd: LCD instancecolumn: Column position (0-based)line: Line position (0-based)
Example
Elcdx.move(lcd, 5, 1) # Move to column 5, line 1
Displays text on the LCD.
Parameters
lcd: LCD instancetext: Text to displayopts: Display options:show_cursor- Show cursor (default: false):scroll- Enable scrolling for long text (default: true)
Examples
Elcdx.print(lcd, "Hello World")
Elcdx.print(lcd, "Long text that will scroll", scroll: true)
Elcdx.print(lcd, "Cursor visible", show_cursor: true)
@spec start_link(String.t(), [start_option()]) :: {:ok, t()} | {:error, term()}
Starts a new LCD connection.
Parameters
device: UART device path (e.g., "/dev/ttyUSB0")opts: Optional configuration:speed- UART baud rate (default: 19200):lines- Number of display lines (default: 2):columns- Number of display columns (default: 16)
Examples
{:ok, lcd} = Elcdx.start_link("/dev/ttyUSB0")
{:ok, lcd} = Elcdx.start_link("/dev/ttyUSB0", speed: 9600, lines: 4, columns: 20)
@spec stop(t()) :: :ok
Stops the LCD connection and cleans up resources.
Example
Elcdx.stop(lcd)