Skip to content

Commit

Permalink
Added (fixed) Liquid_Crystal_I2C class;
Browse files Browse the repository at this point in the history
In LiquidCrystal_Base class changed <begin> function. Now virtual function <send> is used instead of <write4bits> to initialize HD44780;
Changed <send> function: now parameter mode is used to indicate if object is in INIT_MODE or inited and sending COMMAND/DATA;
Functions like: begin and init are now virtual;
Removed from classes <_initialized> flag;
Updated all examples with extention <.pde> to <.ino>;
Added defines for default values of columns, lines, i2c address;
Parameters: _cols, _rows, _addr now have default values;
Added new begin function with parameters like in standart LiquidCrystal class, so LiquidCrystal_I2C class objects now can have same initialization as standart Arduino library;
Added setCursor function in LiquidCrystal_Base class;
In LiquidCrystal_Base class functions: begin(uint8_t cols, uint8_t rows...), write4bits, send are now pure virtual;
Added (fixed) example <AllSymbols.ino>: showcase of all symbols in lcd memory;
Changed example <Autoscroll.ino> to work with both current types of lcd objects (normal, i2c). Base class object pointer is used.
For now all functions are public for developing purpose. In next version functions for sending information, initializing will become private/protected;
For now only avr  architecture is supported and tested;
  • Loading branch information
VladVanyuk committed Jan 31, 2024
1 parent 23d58ed commit b271b0c
Show file tree
Hide file tree
Showing 13 changed files with 471 additions and 181 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/settings.json
142 changes: 142 additions & 0 deletions examples/AllSymbols/AllSymbols.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

uint8_t bell[8] = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t note[8] = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
uint8_t clock[8] = {0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duck[8] = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
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,
};

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

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

uint8_t snow[8] =
{
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();
lcd2.init();

lcd.createChar(0, bell);
lcd.createChar(1, note);
lcd.createChar(2, clock);
lcd.createChar(3, heart);
lcd.createChar(4, duck);
lcd.createChar(5, check);
lcd.createChar(6, cross);
lcd.createChar(7, retarrow);

lcd2.createChar(0, happy);
lcd2.createChar(1, wow);
lcd2.createChar(2, anchor);
lcd2.createChar(3, snow);

lcd.print("LCD Memory");
lcd2.print("LCD Memory");

delay(5000);
displayKeyCodes();
}

void keyCodes2004(uint8_t i)
{
lcd.clear();
lcd.print("Codes 0x");
lcd.print(i, HEX);
lcd.print("-0x");
lcd.print(i + 16, HEX);
lcd.setCursor(0, 1);

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

}

void keyCodes1602(uint8_t i)
{
lcd2.clear();
lcd2.print("Codes 0x");
lcd2.print(i, HEX);
lcd2.print("-0x");
lcd2.print(i + 16, HEX);
lcd2.setCursor(0, 1);

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

}

// display all keycodes
void displayKeyCodes(void)
{
uint8_t i = 0;

while (1)
{

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

i += 16;
}
}

void loop()
{
displayKeyCodes();
}
48 changes: 37 additions & 11 deletions examples/Autoscroll/Autoscroll.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,73 @@
by Tom Igoe
modified 7 Nov 2016
by Arturo Guadalupi
modified 30 Nov 2024
by Vladislav Vanyuk
This example code is in the public domain.
https://docs.arduino.cc/learn/electronics/lcd-displays#autoscroll-example
https://github.com/arduino-libraries/LiquidCrystal
*/

// #define TYPE_LCD
#define TYPE_LCD_I2C
#include <LiquidCrystal_Base.h>

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(rs, en, d4, d5, d6, d7);
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)

#endif



void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);

#ifdef TYPE_LCD
lcd = &lcd_normal;
Serial.println("normal");
#elif defined (TYPE_LCD_I2C)
lcd = &lcd_i2c;
Serial.println("i2c");
#endif
lcd->begin(20, 4);
lcd->clear();
}

void loop() {
// set the cursor to (0,0):
lcd.setCursor(0, 0);
lcd->setCursor(0, 0);
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
lcd->print(thisChar);
delay(500);
}

// set the cursor to (16,1):
lcd.setCursor(16, 1);
lcd->setCursor(16, 1);
// set the display to automatically scroll:
lcd.autoscroll();
lcd->autoscroll();
// print from 0 to 9:
for (int thisChar = 0; thisChar < 10; thisChar++) {
lcd.print(thisChar);
lcd->print(thisChar);
delay(500);
}
// turn off automatic scrolling
lcd.noAutoscroll();
lcd->noAutoscroll();

// clear screen for the next loop:
lcd.clear();
lcd->clear();
}
File renamed without changes.
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=LiquidCrystal
version=1.1.0
version=1.1.1
author=Arduino, Adafruit
maintainer=VladVanyuk <vladvanyuk@gmail.com>
sentence=Allows you to create general LCD object and use same methods in derived (LCDs) classes.
paragraph=Virtual base class abstraction allows you to use one library for LiquidCrystal and LiquidCrystal_I2C (LCDs).
category=Display
url=https://github.com/VladVanyuk/LiquidCrystal
architectures=*
architectures=avr
Loading

0 comments on commit b271b0c

Please sign in to comment.