Skip to content

Commit

Permalink
New version of LCD base class:
Browse files Browse the repository at this point in the history
1) LCD and LCD_I2C now works together;
2) Added documentation in extras;
3) Moved defines in separate file;
4) Changed all examples to work with base class LCD;
5) Reworked virtual function send, write;
6) New initialization variants;
7) Added new files to gitignore
8) Added private functions for bit flags controlling in base LCD class;
9) Added destructor for all classes;
10) In base LCD class changed to protected: _cols, _rows, _displayfunction, _displaycontrol, _displaymode;
11) Added DEFAULT values as defines: LCD_DEFAULT_COLS,  LCD_DEFAULT_ROWS, LCD_DEFAULT_ADDR, LCD_BACKLIGHT;
12) Added variations of functiond to non _AVR_ boards;
  • Loading branch information
VladVanyuk committed Feb 10, 2024
1 parent b271b0c commit ec029d7
Show file tree
Hide file tree
Showing 28 changed files with 687 additions and 765 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
.vscode/settings.json
.vscode

.github/*
.github
.codespellrc
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cmake_minimum_required(VERSION 3.5)

idf_component_register(SRCS "LiquidCrystal_Base.cpp" "LiquidCrystal.cpp" "LiquidCrystal_I2C.cpp"
INCLUDE_DIRS "."
INCLUDE_DIRS ".", "./coreLCD"
REQUIRES arduino)

project(LiquidCrystal)
project(LiquidCrystal_Base)
2 changes: 2 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ TIP: To find the latest versions, refer to https://github.com/VladVanyuk/BaseLiq

* Added https://github.com/MartyMacGyver/Arduino_I2C_Scanner/tree/masterp[I2C_scanner] in examples

* Added https://github.com/mrkaleArduinoLib/LiquidCrystal_I2C/tree/master[Complete Test] in examples. Also added readme file.

=== License
This project is released under a {License} License.

Expand Down
Binary file added docs/extras/info/2004_I2C_Serial_LCD_Display.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/extras/info/2004_Pinout.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/extras/info/Character_Set.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions docs/extras/info/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// LiquidCrystal_I2C V2.0 - Mario H. atmega@xs4all.nl
// Mods for Chinese I2C converter board - Murray R. Van Luyn. vanluynm@iinet.net.au

The LiquidCrystal_I2C library is a modified version of the standard LiquidCrystal library as found on
the Arduino website.
This library is intended to be used when a parallel HD44780 compatible LCD is controlled over I2C using
a Chinese PCF8574 extender.
4 of the 8 outputs are used for LCD data lines 4 to 7.
4 outputs are used for the Enable, register-select, Read/Write and backlight control lines.

The Chinese PCF8574 extender is available in two versions, the PCF8574 and the PCF8574A.
The only difference between the two is the I2C base address.
The base address for the PCF8574 is 0x27 and the base address for the PCF8574A is 0x4E.
The examples included in this zip file assume the use of an PCF8574 set for address 0x27
(A0, A1 and A3 un-linked, so pulled high).

For PCF8574 the addressing is:

Jp3 Jp2 Jp1
A2 A1 A0 Dec Hex
L L L 32 0x20
L L H 33 0x21
L H L 34 0x22
L H H 35 0x23
H L L 36 0x24
H L H 37 0x25
H H L 38 0x26
H H H 39 0x27

For PCF8574A the addressing is:

Jp3 Jp2 Jp1
A2 A1 A0 Dec Hex
L L L 56 0x38
L L H 57 0x39
L H L 64 0x40
L H H 74 0x4A
H L L 75 0x4B
H L H 76 0x4C
H H L 77 0x4D
H H H 78 0x4E

For compatibility reasons this library contains some aliases for functions that are known under different
names in other libraries. This should make it fairly easy to implement the library in existing sketches
without changing to much code.
Functions not supported by this library will return nothing at all and in case a return value is expected
the function will return 0.
105 changes: 58 additions & 47 deletions examples/AllSymbols/AllSymbols.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_Base.h>

uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
Expand All @@ -11,57 +10,57 @@ uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t retarrow[8] = {0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};

uint8_t happy[8] =
{
0b00000,
0b10001,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000,
0b00000,
{
0b00000,
0b10001,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000,
0b00000
};

uint8_t wow[8] =
{
0b00000,
0b10001,
0b00000,
0b01110,
0b10001,
0b01110,
0b00000,
0b00000,
{
0b00000,
0b10001,
0b00000,
0b01110,
0b10001,
0b01110,
0b00000,
0b00000
};

uint8_t anchor[8] =
{
0b01110,
0b01010,
0b01110,
0b00100,
0b10101,
0b10101,
0b01110,
0b00100};
{
0b01110,
0b01010,
0b01110,
0b00100,
0b10101,
0b10101,
0b01110,
0b00100
};

uint8_t snow[8] =
{
0b01000,
0b11101,
0b01011,
0b00001,
0b00100,
0b01110,
0b00100,
0b10000};
{
0b01000,
0b11101,
0b01011,
0b00001,
0b00100,
0b01110,
0b00100,
0b10000
};

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
LiquidCrystal_I2C lcd2(0x26, 16, 2);

LiquidCrystal_I2C *lcd_ptr;

void setup()
{
lcd.init();
Expand Down Expand Up @@ -94,14 +93,27 @@ void keyCodes2004(uint8_t i)
lcd.print("Codes 0x");
lcd.print(i, HEX);
lcd.print("-0x");
lcd.print(i + 16, HEX);
lcd.print(i + 60, HEX);
lcd.setCursor(0, 1);

for (int j = 0; j < 16; j++)
for (int j = 0; j < 20; j++)
{
lcd.write(i + j);
}

i+=20;
lcd.setCursor(0, 2);
for (int j = 0; j < 20; j++)
{
lcd.write(i + j);
}

i+=20;
lcd.setCursor(0, 3);
for (int j = 0; j < 20; j++)
{
lcd.write(i + j);
}

}

void keyCodes1602(uint8_t i)
Expand All @@ -117,22 +129,21 @@ void keyCodes1602(uint8_t i)
{
lcd2.write(i + j);
}

}

// display all keycodes
void displayKeyCodes(void)
{
// symbols 0x10-0x20 are usualy shown as empty
uint8_t i = 0;

while (1)
{

keyCodes2004(i);
keyCodes1602(i);
delay(5000);
delay(10000);

i += 16;
i += 16;
}
}

Expand Down
16 changes: 7 additions & 9 deletions examples/Autoscroll/Autoscroll.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
modified 30 Nov 2024
modified 2 Feb 2024
by Vladislav Vanyuk
This example code is in the public domain.
Expand All @@ -40,29 +40,27 @@
https://github.com/arduino-libraries/LiquidCrystal
*/


// choose what connection type your display is
// #define TYPE_LCD
#define TYPE_LCD_I2C

// include the library code:
#include <LiquidCrystal_Base.h>

// virtual base class pointer to an object
LiquidCrystal_Base *lcd;

#if (defined TYPE_LCD)
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the Arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd_normal(rs, en, d4, d5, d6, d7);

#elif (defined TYPE_LCD_I2C)

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd_i2c(0x27, 20, 4); //(0x27, 16, 2)

LiquidCrystal_I2C lcd_i2c(0x27, 16, 2) //(0x27, 20, 4)
#endif



void setup() {
Serial.begin(9600);

Expand Down
32 changes: 25 additions & 7 deletions examples/Blink/Blink.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
modified 2 Feb 2024
by Vladislav Vanyuk
This example code is in the public domain.
Expand All @@ -40,25 +42,41 @@
*/

// include the library code:
#include <LiquidCrystal.h>
#include <LiquidCrystal_Base.h>

#define LCD_TYPE 1 // 0 - LCD, 1 - LCD_I2C

LiquidCrystal_Base *lcd;

#if (LCD_TYPE == 0)
// initialize the library by associating any needed LCD interface pin
// with the Arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
LiquidCrystal lcd_normal(rs, en, d4, d5, d6, d7);
#elif (LCD_TYPE == 1)
LiquidCrystal_I2C lcd_i2c(0x27, 16, 2); //(0x27, 20, 4)
#else
error("Please select the LCD type")
#endif

void setup() {
#if (LCD_TYPE == 0)
lcd = &lcd_normal;
#elif (LCD_TYPE == 1)
lcd = &lcd_i2c;
#endif

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
lcd->begin(16, 2);
// Print a message to the LCD
lcd->print("Cursor Blinking");
}

void loop() {
// Turn off the blinking cursor:
lcd.noBlink();
lcd->noBlink();
delay(3000);
// Turn on the blinking cursor:
lcd.blink();
lcd->blink();
delay(3000);
}
Loading

0 comments on commit ec029d7

Please sign in to comment.