Skip to content

Commit

Permalink
Library is now compatible with the New LiquidCrystal library
Browse files Browse the repository at this point in the history
Added support for using either the standard Arduino LiquidCrystal
library of the New LiquidCrystal library.

BigCrystal now contains an lcd instance rather than using extending the
LiquidCrystal class. This is a breaking change and sketches using
v1.0.0 of BigCrystal will require modification.
  • Loading branch information
gregington committed Oct 25, 2013
1 parent d916694 commit 428cdb4
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 98 deletions.
34 changes: 9 additions & 25 deletions BigCrystal.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,26 @@
#include "BigFont.h"
#include "BigCrystal.h"

BigCrystal::BigCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) :
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) {
init();
#ifndef LiquidCrystal_h // New liquid crystal library
BigCrystal::BigCrystal(LCD *display) {
#else // Standard library
BigCrystal::BigCrystal(LiquidCrystal *display) {
#endif
_display = display;
createCustomChars();
}

BigCrystal::BigCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) :
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7) {
init();
}

BigCrystal::BigCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) :
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3) {
init();
}

BigCrystal::BigCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) :
LiquidCrystal(rs, enable, d0, d1, d2, d3) {
init();
}

/* Creates custom font shapes for LCD characters 0 through to 7
* used in displaying big fonts
*/
void BigCrystal::init() {
void BigCrystal::createCustomChars() {
for (uint8_t i = 0; i < 8; i++) {
uint8_t customChar[8];
for (uint8_t j = 0; j < 8; j++) {
customChar[j] = pgm_read_byte(BF_fontShapes + (i * 8) + j);
}
createChar(i, customChar);
_display->createChar(i, customChar);
}
}

Expand Down
90 changes: 54 additions & 36 deletions BigCrystal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,42 @@
#define BigCrystal_h

#include "BigFont.h"
#include <Arduino.h>
#include <Print.h>

#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#include <LiquidCrystal.h>
#ifndef LiquidCrystal_h // Using the new LiquidCrystal library
#ifdef LiquidCrystal_4bit_h || LiquidCrystal_I2C_h || _LIQUIDCRYSTAL_SR_ || _LIQUIDCRYSTAL_SR2W_ || _LIQUIDCRYSTAL_SR3W_H_ // Using the New LiquidCrystal library
#include "LCD.h"
#else
#error You must install New LiquidCrystal library to work with non-4bit projects: http:/bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
#endif
#endif


/* Class that displays text on a Hitachi HD44780 compatible display. As well
* as displaying standard text, doubli height characters can also be displayed.
*/
class BigCrystal : public LiquidCrystal {
class BigCrystal : public Print {
public:
/* Creates a BigCrystal instance.
* Parameters:
* rs: the Arduino pin that is connected to the RS pin on the display.
* enable: the Arduino pin that is connected to the enable pin on the display.
* d4 - d7: the Arduino pins connected to pins d4 to d7 on the display.
* lcd: A LiquidCrystal or LCD instance.
*/
#ifndef LiquidCrystal_h // New liquid crystal library
BigCrystal(LCD *display);
#else
BigCrystal(LiquidCrystal *display);
#endif
BigCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);

/* Creates a BigCrystal instance.
* Parameters:
* rs: the Arduino pin that is connected to the RS pin on the display.
* rw: the Arduino pin that is connected to the RW pin on the display.
* enable: the Arduino pin that is connected to the enable pin on the display.
* d4 - d7: the Arduino pins connected to pins d4 to d7 on the display.
*/
BigCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);

/* Creates a BigCrystal instance.
* Parameters:
* rs: the Arduino pin that is connected to the RS pin on the display.
* rw: the Arduino pin that is connected to the RW pin on the display.
* enable: the Arduino pin that is connected to the enable pin on the display.
* d0 - d7: the Arduino pins connected to pins d0 to d7 on the display.
*/
BigCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

/* Creates a BigCrystal instance.
* Parameters:
* rs: the Arduino pin that is connected to the RS pin on the display.
* enable: the Arduino pin that is connected to the enable pin on the display.
* d0 - d7: the Arduino pins connected to pins d0 to d7 on the display.
*/
BigCrystal(uint8_t rs, uint8_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

/* Returns the width in columns of the specified character.
* If the character cannot be printed big, then zero is returned.
* Parameters:
Expand Down Expand Up @@ -84,13 +72,43 @@ class BigCrystal : public LiquidCrystal {
* the total width of all printed characters, including all empty spacer columns
*/
uint8_t printBig(char *str, uint8_t col, uint8_t row);

/* Delegate methods to underlying LCD instance */
inline void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS) {
_display->begin(cols, rows, charsize);
}
inline void clear() { _display->clear(); }
inline void home() { _display->home(); }
inline void noDisplay() { _display->noDisplay(); }
inline void display() { _display->display(); }
inline void noBlink() { _display->noBlink(); }
inline void blink() { _display->blink(); }
inline void noCursor() { _display->noCursor(); }
inline void cursor() { _display->cursor(); }
inline void scrollDisplayLeft() { _display->scrollDisplayLeft(); }
inline void scrollDisplayRight() { _display->scrollDisplayRight(); }
inline void leftToRight() { _display->leftToRight(); }
inline void rightToLeft() { _display->rightToLeft(); }
inline void autoscroll() { _display->autoscroll(); }
inline void noAutoscroll() { _display->noAutoscroll(); }
inline void createChar(uint8_t location, uint8_t charmap[]) { _display->createChar(location, charmap); }
inline void setCursor(uint8_t col, uint8_t row) { _display->setCursor(col, row); }
inline virtual size_t write(uint8_t value) { _display->write(value); }

using Print::write;
private:
void init();
void createCustomChars();
uint8_t getWidthFromTableCode(uint8_t tableCode);
uint8_t* getTable(uint8_t tableCode);
void getTableCodeAndIndex(char c, uint8_t &tableCode, uint8_t &index);
void clearColumn(uint8_t row, uint8_t col);
char toUpperCase(char c);
bool supported(char c);
#ifndef LiquidCrystal_h // Using New LquidCrystal library
LCD *_display;
#else
LiquidCrystal *_display;
#endif

};
#endif
40 changes: 26 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
BigCrystal
==========

Arduino Library for displaying double height characters on an LCD display.

A corresponding library, [BigCrystalTWI](https://github.com/gregington/BigCrystalTWI)
is available to use if connecting the LCD using I<sup>2</sup>C.
Arduino Library for displaying double height characters on an LCD display. This library is
compatible with the standard LiquidCrystal library dictributed with the Arduino IDE and
also with the [New LiquidCrystal](https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home)
which is a drop in replacement for the standard library.

The New LiquidCrystal library supports connections to LCDs using
* 4 bit parallel interface
* 8 bit parallel interface
* I<sup>2</sup>C expansion boards
* Shift registers

Note that this version of the library is incompatible with version 1 to implement compatibility
with the New LiquidCrystal library.

Contributors
------------
Thanks to Bill Perry who reviewed the original code and suggested I base this library on
the New LiquidCrystal library by F. Malpartida. Thak you also to Tim Eckel who wrote the
[LCDBitmap](http://code.google.com/p/arduino-lcd-bitmap/) library whose code gave me insight
on how to make this library compatible with both the standard LiquidCrystal and New
LiquidCrystal libraries.

Usage
-----

To use BigCrystal, the sketch will need the following includes:

#include <LiquidCrystal.h>
#include <BigCrystal.h>

Creating the LCD object is similar to the [LiquidCrystal library](https://github.com/Stephanie-Maks/Arduino-LiquidTWI);
the pin numbers on the Arduino that connect to the LCD need to be specified.
All constructors available in LiquidCrystal are available in BigCrystal. For example:
BigCrystal is implemented as a wrapper around an LCD object, created using either the standard or new LiquidCrystal libraries. The lcd object is passed through to the BigCrystal constructor.

BigCrystal lcd(22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32);
BigCrystal exposes all LiquidCrystal public methods and delegates to the underlying object. This
means that once the BigCrytal object is created, you just need to reference that instance instead
of using both the BigCrystal instance and the underling LiquidCrystal instance.

The following methods, in addition to those in LiquidTWI are available:
The following methods are available to display double height characters:
* writeBig(char c, uint8_t row, uint8_t col) - writes a single large character to the specified coordinates.
* printBig(char* str, uint8_t row, uint8_t col) - writes a String to the specified coordinates.
* widthBig(char c) - returns the width in characters of the specified large character.
Expand Down
33 changes: 33 additions & 0 deletions examples/NewLCD_I2C/AllCharacters/AllCharacters.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <BigCrystal.h>

LiquidCrystal_I2C lcd(0x38); // Set the LCD I2C address
BigCrystal bigCrystal(&lcd);

void setup() {
bigCrystal.begin(20, 4); // Set to your LCD size
}

void loop() {
// Displays all characters is big front from 0x00 (space) to 0x5A (Z)
for (char c = 0x20; c <= 0x5A; c++) {
// Clear out the maximum width so that pars of wider
// characters are removed
clear();

bigCrystal.writeBig(c, 0, 0);
bigCrystal.setCursor(7, 0);
bigCrystal.write(c);
delay(1000);
}
}

void clear() {
for (int i = 0; i < 5; i++) {
bigCrystal.setCursor(i, 0);
bigCrystal.print(' ');
bigCrystal.setCursor(i, 1);
bigCrystal.print(' ');
}
}
16 changes: 16 additions & 0 deletions examples/NewLCD_I2C/PrintString/PrintString.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <BigCrystal.h>

// Set up according to your LCD pins
LiquidCrystal_I2C lcd(0x38); // Set the LCD I2C address
BigCrystal bigCrystal(&lcd);

void setup() {
bigCrystal.begin(20, 4);

bigCrystal.printBig("10:22", 0, 0);
}

void loop() {
}
34 changes: 34 additions & 0 deletions examples/NewLCD_SR/AllCharacters/AllCharacters.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <LiquidCrystal_SR.h>
#include <LCDBitmap.h>
#include <BigCrystal.h>

// Set up according to your shift register pins
LiquidCrystal_SR lcd(8, 7, TWO_WIRE);
BigCrystal bigCrystal(&lcd);

void setup() {
bigCrystal.begin(20, 4); // Set to your LCD size
}

void loop() {
// Displays all characters is big front from 0x00 (space) to 0x5A (Z)
for (char c = 0x20; c <= 0x5A; c++) {
// Clear out the maximum width so that pars of wider
// characters are removed
clear();

bigCrystal.writeBig(c, 0, 0);
bigCrystal.setCursor(7, 0);
bigCrystal.write(c);
delay(1000);
}
}

void clear() {
for (int i = 0; i < 5; i++) {
bigCrystal.setCursor(i, 0);
bigCrystal.print(' ');
bigCrystal.setCursor(i, 1);
bigCrystal.print(' ');
}
}
16 changes: 16 additions & 0 deletions examples/NewLCD_SR/PrintString/PrintString.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <LiquidCrystal_SR.h>
#include <LCDBitmap.h>
#include <BigCrystal.h>

// Set up according to your shift register pins
LiquidCrystal_SR lcd(8, 7, TWO_WIRE);
BigCrystal bigCrystal(&lcd);

void setup() {
bigCrystal.begin(20, 4);

bigCrystal.printBig("10:22", 0, 0);
}

void loop() {
}
33 changes: 33 additions & 0 deletions examples/NewLCD_SR2W/AllCharacters/AllCharacters.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <LiquidCrystal_SR2W.h>
#include <BigCrystal.h>

// Change to your shift register pins
LiquidCrystal_SR2W lcd(2, 3);
BigCrystal bigCrystal(&lcd);

void setup() {
bigCrystal.begin(20, 4); // Set to your LCD size
}

void loop() {
// Displays all characters is big front from 0x00 (space) to 0x5A (Z)
for (char c = 0x20; c <= 0x5A; c++) {
// Clear out the maximum width so that pars of wider
// characters are removed
clear();

bigCrystal.writeBig(c, 0, 0);
bigCrystal.setCursor(7, 0);
bigCrystal.write(c);
delay(1000);
}
}

void clear() {
for (int i = 0; i < 5; i++) {
bigCrystal.setCursor(i, 0);
bigCrystal.print(' ');
bigCrystal.setCursor(i, 1);
bigCrystal.print(' ');
}
}
15 changes: 15 additions & 0 deletions examples/NewLCD_SR2W/PrintString/PrintString.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <LiquidCrystal_SR2W.h>
#include <BigCrystal.h>

// Change to your shift register pins
LiquidCrystal_SR2W lcd(2, 3);
BigCrystal bigCrystal(&lcd);

void setup() {
bigCrystal.begin(20, 4);

bigCrystal.printBig("10:22", 0, 0);
}

void loop() {
}
Loading

0 comments on commit 428cdb4

Please sign in to comment.