24inline void sleep_ms(uint32_t time) {delay(time);}
25inline void sleep_us(uint64_t time) {delayMicroseconds(time);}
52 static constexpr byte LCD_CLEARDISPLAY = 0x01;
53 static constexpr byte LCD_RETURNHOME = 0x02;
54 static constexpr byte LCD_ENTRYMODESET = 0x04;
55 static constexpr byte LCD_DISPLAYCONTROL = 0x08;
56 static constexpr byte LCD_DISPLAYSHIFT = 0x10;
57 static constexpr byte LCD_FUNCTIONSET = 0x20;
58 static constexpr byte LCD_SETCGRAMADDR = 0x40;
59 static constexpr byte LCD_SETDDRAMADDR = 0x80;
63 static constexpr byte LCD_ENTRYRIGHT = 0x00;
64 static constexpr byte LCD_ENTRYLEFT = 0x02;
65 static constexpr byte LCD_DISPLAYENTRYSHIFT = 0x01;
66 static constexpr byte LCD_NODISPLAYENTRYSHIFT = 0x00;
70 static constexpr byte LCD_DISPLAYON = 0x04;
71 static constexpr byte LCD_DISPLAYOFF = 0x00;
72 static constexpr byte LCD_CURSORON = 0x02;
73 static constexpr byte LCD_CURSOROFF = 0x00;
74 static constexpr byte LCD_BLINKON = 0x01;
75 static constexpr byte LCD_BLINKOFF = 0x00;
79 static constexpr byte LCD_DISPLAYMOVE = 0x08;
80 static constexpr byte LCD_CURSORMOVE = 0x00;
81 static constexpr byte LCD_MOVERIGHT = 0x04;
82 static constexpr byte LCD_MOVELEFT = 0x00;
85 static constexpr byte LCD_8BITMODE = 0x10;
86 static constexpr byte LCD_4BITMODE = 0x00;
87 static constexpr byte LCD_2LINE = 0x08;
88 static constexpr byte LCD_1LINE = 0x00;
91 static constexpr byte LCD_BACKLIGHT = 0x08;
92 static constexpr byte LCD_NOBACKLIGHT = 0x00;
94 static constexpr byte En = 0x4;
95 static constexpr byte Rw = 0x2;
96 static constexpr byte Rs = 0x1;
98 static constexpr byte ENABLE = En;
103 static constexpr byte LCD_CHARACTER = 1;
104 static constexpr byte LCD_COMMAND = 0;
106 static constexpr byte MAX_LINES = 4;
107 static constexpr byte MAX_CHARS = 20;
110 byte _displayfunction;
111 byte _displaycontrol;
119 uint8_t row_address_offset[
MAX_LINES] = {0x80, 0xC0, 0x80 + 20, 0xC0 + 20};
141 #ifndef BUFFER_LENGTH
142 #ifdef WIRE_BUFFER_SIZE
143 static constexpr size_t BUFFER_LENGTH = WIRE_BUFFER_SIZE;
145 static constexpr size_t BUFFER_LENGTH = 30;
149 static constexpr size_t BUFFER_LENGTH = 128;
152 byte _buffer[BUFFER_LENGTH];
159 size_t _bufferIn = 0;
167 i2c_inst *I2C_instance {
nullptr};
178 void write_byte(
byte val,
bool Enable_Buffering =
false)
noexcept;
189 void send_byte(
byte val,
int mode,
bool Enable_Buffering =
false)
noexcept;
197 void init()
noexcept;
257 LCD_I2C(uint8_t lcd_addr, uint8_t lcd_cols, uint8_t lcd_rows, uint8_t charsize =
LCD_5x8DOTS)
noexcept;
268 inline void begin() noexcept {
308 LCD_I2C(
byte address,
byte columns,
byte rows, i2c_inst *I2C = PICO_DEFAULT_I2C_INSTANCE)
noexcept;
330 void writeChar(
byte val,
bool Enable_Buffering =
false) noexcept;
342 void writeString(const
char str[],
bool Enable_Buffering = false) noexcept;
370 inline size_t write(uint8_t c)
noexcept
387 size_t write(
const uint8_t *buffer,
size_t size,
bool Enable_Buffering =
false) noexcept;
395 inline
size_t write(const
char *str) noexcept
397 if (str == NULL)
return 0;
398 return write((
const uint8_t *)str, strlen(str));
412 inline size_t write(
const char *buffer,
size_t size,
bool Enable_Buffering =
false) noexcept
414 return write((
const uint8_t *)buffer, size, Enable_Buffering);
441 void setCursor(
byte line,
byte position,
bool Enable_Buffering=
false) noexcept;
469 void setCursor(
byte position,
byte line,
bool Enable_Buffering=
false) noexcept;
480 void clear(
void)
noexcept;
489 void home(
void)
noexcept;
549 void cursor(
void)
noexcept;
575 void blink(
void)
noexcept;
681 void createChar(
byte charnum,
const byte char_map[])
noexcept;
713 int show(
void)
noexcept;
721#ifndef I2C_Setup_defined
723 #define I2C_Setup_defined
748 extern "C" int LCD_I2C_Setup(i2c_inst_t* I2C, uint SDA_Pin, uint SCL_Pin, uint I2C_Clock)
noexcept;
#define MAX_LINES
Definition: LCD_I2C-C.cpp:31
A class for efficiently driving an LDC display connected to the I2C bus on Arduino or Pi Pico.
Definition: LCD_I2C.hpp:45
void blink(void) noexcept
Display the blinking inverted cursor at the current cursor location.
Definition: LCD_I2C.cpp:243
void scrollDisplayRight(void) noexcept
Scrolls the display and cursor one position to the right. home() will restore it to its original posi...
Definition: LCD_I2C.cpp:272
void noAutoscroll(void) noexcept
Turns off automatic scrolling of the display.
Definition: LCD_I2C.cpp:283
void createChar(byte charnum, const byte char_map[]) noexcept
Create a custom character.
Definition: LCD_I2C.cpp:301
void cursor(void) noexcept
Display the underline cursor at the current cursor location.
Definition: LCD_I2C.cpp:231
void rightToLeft(void) noexcept
Sets the text direction to right to left. Each character output advances the cursor one position to t...
Definition: LCD_I2C.cpp:289
void autoscroll(void) noexcept
Turns on automatic scrolling of the display.
Definition: LCD_I2C.cpp:277
void writeString(const char str[], bool Enable_Buffering=false) noexcept
Output a string to the screen. Naming is more in the style of the Pico SDK, and the Enable_Buffering ...
Definition: LCD_I2C.cpp:132
void backlight(void) noexcept
Turn on the display backlight.
Definition: LCD_I2C.cpp:219
int show(void) noexcept
Empties the buffer to "show" any data not yet output to the screen.
Definition: LCD_I2C.cpp:198
static constexpr byte LCD_5x8DOTS
needed for Arduino Constructor
Definition: LCD_I2C.hpp:216
void scrollDisplayLeft(void) noexcept
Scrolls the display and cursor one position to the left. home() will restore it to its original posit...
Definition: LCD_I2C.cpp:267
void noBacklight(void) noexcept
Turn off the display backlight
Definition: LCD_I2C.cpp:225
void noDisplay(void) noexcept
Turns the display off without modifying data on it.
Definition: LCD_I2C.cpp:261
void printstr(const char str[]) noexcept
An alias for writeString (for compatibility with earlier programs)
Definition: LCD_I2C.hpp:349
size_t write(uint8_t c) noexcept
Override the write byte method of the Arduino print class.
Definition: LCD_I2C.hpp:370
void noBlink(void) noexcept
Disable the blinking inverted cursor at the current cursor location.
Definition: LCD_I2C.cpp:249
void setBacklight(uint8_t newVal) noexcept
Set the backlight to a given value.
Definition: LCD_I2C.hpp:513
void writeChar(byte val, bool Enable_Buffering=false) noexcept
Output a character to the screen.
Definition: LCD_I2C.cpp:144
void cursor_on() noexcept
Alias for cursor() to turn the underline cursor on.
Definition: LCD_I2C.hpp:554
void blink_on() noexcept
Alias for blink() to display the blinking inverted cursor.
Definition: LCD_I2C.hpp:581
void noCursor(void) noexcept
Hides the underline cursor at the current cursor location.
Definition: LCD_I2C.cpp:237
size_t write(const char *buffer, size_t size, bool Enable_Buffering=false) noexcept
Override the write buffer of type char method from Arduino print.
Definition: LCD_I2C.hpp:412
void cursor_off() noexcept
An alias for noCursor to turn off the underline cursor.
Definition: LCD_I2C.hpp:567
void display(void) noexcept
Turns the display on without modifying data on it.
Definition: LCD_I2C.cpp:255
void leftToRight(void) noexcept
Sets the text direction to left to right. Each character output advances the cursor one position to t...
Definition: LCD_I2C.cpp:295
static constexpr uint8_t CUSTOM_SYMBOL_SIZE
A reminder of the size of custom character arrays.
Definition: LCD_I2C.hpp:211
void home(void) noexcept
"Home" the display.
Definition: LCD_I2C.cpp:111
void clear(void) noexcept
Clear the display.
Definition: LCD_I2C.cpp:105
void setCursor(byte line, byte position, bool Enable_Buffering=false) noexcept
Move the input cursor to a location on the screen.
Definition: LCD_I2C.cpp:122
static constexpr byte LCD_5x10DOTS
needed for Arduino Constructor
Definition: LCD_I2C.hpp:214
LCD_I2C(byte address, byte columns, byte rows, i2c_inst *I2C=PICO_DEFAULT_I2C_INSTANCE) noexcept
The Pi Pico Constructor.
Definition: LCD_I2C.cpp:44
void blink_off() noexcept
Alias for noBlink() to turn off the blinking inverted cursor.
Definition: LCD_I2C.hpp:595
void load_custom_character(uint8_t char_num, uint8_t *rows) noexcept
An alias for createChar() for loading custom character data.
Definition: LCD_I2C.hpp:688
int LCD_I2C_Setup(i2c_inst_t *I2C, uint SDA_Pin, uint SCL_Pin, uint I2C_Clock) noexcept
Helper function to set up the I2C bus on Pi Pico.
Definition: LCD_I2C.cpp:314