From 904942006ea36cd5895962d5274e92ea3729dc2c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 4 Jan 2012 15:14:51 +0100 Subject: [PATCH 01/19] Moved libraries folder inside platform folder. Now libraries and examples are searched per board/platform --- LiquidCrystal.cpp | 310 ------------------- LiquidCrystal.h | 106 ------- examples/Autoscroll/Autoscroll.ino | 73 ----- examples/Blink/Blink.ino | 61 ---- examples/Cursor/Cursor.ino | 60 ---- examples/CustomCharacter/CustomCharacter.ino | 138 --------- examples/Display/Display.ino | 60 ---- examples/HelloWorld/HelloWorld.ino | 58 ---- examples/Scroll/Scroll.ino | 85 ----- examples/SerialDisplay/SerialDisplay.ino | 65 ---- examples/TextDirection/TextDirection.ino | 87 ------ examples/setCursor/setCursor.ino | 71 ----- keywords.txt | 37 --- 13 files changed, 1211 deletions(-) delete mode 100644 LiquidCrystal.cpp delete mode 100755 LiquidCrystal.h delete mode 100644 examples/Autoscroll/Autoscroll.ino delete mode 100644 examples/Blink/Blink.ino delete mode 100644 examples/Cursor/Cursor.ino delete mode 100644 examples/CustomCharacter/CustomCharacter.ino delete mode 100644 examples/Display/Display.ino delete mode 100644 examples/HelloWorld/HelloWorld.ino delete mode 100644 examples/Scroll/Scroll.ino delete mode 100644 examples/SerialDisplay/SerialDisplay.ino delete mode 100644 examples/TextDirection/TextDirection.ino delete mode 100644 examples/setCursor/setCursor.ino delete mode 100755 keywords.txt diff --git a/LiquidCrystal.cpp b/LiquidCrystal.cpp deleted file mode 100644 index 0653487..0000000 --- a/LiquidCrystal.cpp +++ /dev/null @@ -1,310 +0,0 @@ -#include "LiquidCrystal.h" - -#include -#include -#include -#include "Arduino.h" - -// When the display powers up, it is configured as follows: -// -// 1. Display clear -// 2. Function set: -// DL = 1; 8-bit interface data -// N = 0; 1-line display -// F = 0; 5x8 dot character font -// 3. Display on/off control: -// D = 0; Display off -// C = 0; Cursor off -// B = 0; Blinking off -// 4. Entry mode set: -// I/D = 1; Increment by 1 -// S = 0; No shift -// -// Note, however, that resetting the Arduino doesn't reset the LCD, so we -// can't assume that its in that state when a sketch starts (and the -// LiquidCrystal constructor is called). - -LiquidCrystal::LiquidCrystal(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) -{ - init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7); -} - -LiquidCrystal::LiquidCrystal(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) -{ - init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); -} - -LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) -{ - init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); -} - -LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) -{ - init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); -} - -void LiquidCrystal::init(uint8_t fourbitmode, 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) -{ - _rs_pin = rs; - _rw_pin = rw; - _enable_pin = enable; - - _data_pins[0] = d0; - _data_pins[1] = d1; - _data_pins[2] = d2; - _data_pins[3] = d3; - _data_pins[4] = d4; - _data_pins[5] = d5; - _data_pins[6] = d6; - _data_pins[7] = d7; - - pinMode(_rs_pin, OUTPUT); - // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# - if (_rw_pin != 255) { - pinMode(_rw_pin, OUTPUT); - } - pinMode(_enable_pin, OUTPUT); - - if (fourbitmode) - _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; - else - _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; - - begin(16, 1); -} - -void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { - if (lines > 1) { - _displayfunction |= LCD_2LINE; - } - _numlines = lines; - _currline = 0; - - // for some 1 line displays you can select a 10 pixel high font - if ((dotsize != 0) && (lines == 1)) { - _displayfunction |= LCD_5x10DOTS; - } - - // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! - // according to datasheet, we need at least 40ms after power rises above 2.7V - // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 - delayMicroseconds(50000); - // Now we pull both RS and R/W low to begin commands - digitalWrite(_rs_pin, LOW); - digitalWrite(_enable_pin, LOW); - if (_rw_pin != 255) { - digitalWrite(_rw_pin, LOW); - } - - //put the LCD into 4 bit or 8 bit mode - if (! (_displayfunction & LCD_8BITMODE)) { - // this is according to the hitachi HD44780 datasheet - // figure 24, pg 46 - - // we start in 8bit mode, try to set 4 bit mode - write4bits(0x03); - delayMicroseconds(4500); // wait min 4.1ms - - // second try - write4bits(0x03); - delayMicroseconds(4500); // wait min 4.1ms - - // third go! - write4bits(0x03); - delayMicroseconds(150); - - // finally, set to 4-bit interface - write4bits(0x02); - } else { - // this is according to the hitachi HD44780 datasheet - // page 45 figure 23 - - // Send function set command sequence - command(LCD_FUNCTIONSET | _displayfunction); - delayMicroseconds(4500); // wait more than 4.1ms - - // second try - command(LCD_FUNCTIONSET | _displayfunction); - delayMicroseconds(150); - - // third go - command(LCD_FUNCTIONSET | _displayfunction); - } - - // finally, set # lines, font size, etc. - command(LCD_FUNCTIONSET | _displayfunction); - - // turn the display on with no cursor or blinking default - _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; - display(); - - // clear it off - clear(); - - // Initialize to default text direction (for romance languages) - _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; - // set the entry mode - command(LCD_ENTRYMODESET | _displaymode); - -} - -/********** high level commands, for the user! */ -void LiquidCrystal::clear() -{ - command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero - delayMicroseconds(2000); // this command takes a long time! -} - -void LiquidCrystal::home() -{ - command(LCD_RETURNHOME); // set cursor position to zero - delayMicroseconds(2000); // this command takes a long time! -} - -void LiquidCrystal::setCursor(uint8_t col, uint8_t row) -{ - int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; - if ( row >= _numlines ) { - row = _numlines-1; // we count rows starting w/0 - } - - command(LCD_SETDDRAMADDR | (col + row_offsets[row])); -} - -// Turn the display on/off (quickly) -void LiquidCrystal::noDisplay() { - _displaycontrol &= ~LCD_DISPLAYON; - command(LCD_DISPLAYCONTROL | _displaycontrol); -} -void LiquidCrystal::display() { - _displaycontrol |= LCD_DISPLAYON; - command(LCD_DISPLAYCONTROL | _displaycontrol); -} - -// Turns the underline cursor on/off -void LiquidCrystal::noCursor() { - _displaycontrol &= ~LCD_CURSORON; - command(LCD_DISPLAYCONTROL | _displaycontrol); -} -void LiquidCrystal::cursor() { - _displaycontrol |= LCD_CURSORON; - command(LCD_DISPLAYCONTROL | _displaycontrol); -} - -// Turn on and off the blinking cursor -void LiquidCrystal::noBlink() { - _displaycontrol &= ~LCD_BLINKON; - command(LCD_DISPLAYCONTROL | _displaycontrol); -} -void LiquidCrystal::blink() { - _displaycontrol |= LCD_BLINKON; - command(LCD_DISPLAYCONTROL | _displaycontrol); -} - -// These commands scroll the display without changing the RAM -void LiquidCrystal::scrollDisplayLeft(void) { - command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); -} -void LiquidCrystal::scrollDisplayRight(void) { - command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); -} - -// This is for text that flows Left to Right -void LiquidCrystal::leftToRight(void) { - _displaymode |= LCD_ENTRYLEFT; - command(LCD_ENTRYMODESET | _displaymode); -} - -// This is for text that flows Right to Left -void LiquidCrystal::rightToLeft(void) { - _displaymode &= ~LCD_ENTRYLEFT; - command(LCD_ENTRYMODESET | _displaymode); -} - -// This will 'right justify' text from the cursor -void LiquidCrystal::autoscroll(void) { - _displaymode |= LCD_ENTRYSHIFTINCREMENT; - command(LCD_ENTRYMODESET | _displaymode); -} - -// This will 'left justify' text from the cursor -void LiquidCrystal::noAutoscroll(void) { - _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; - command(LCD_ENTRYMODESET | _displaymode); -} - -// Allows us to fill the first 8 CGRAM locations -// with custom characters -void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) { - location &= 0x7; // we only have 8 locations 0-7 - command(LCD_SETCGRAMADDR | (location << 3)); - for (int i=0; i<8; i++) { - write(charmap[i]); - } -} - -/*********** mid level commands, for sending data/cmds */ - -inline void LiquidCrystal::command(uint8_t value) { - send(value, LOW); -} - -inline size_t LiquidCrystal::write(uint8_t value) { - send(value, HIGH); - return 1; // assume sucess -} - -/************ low level data pushing commands **********/ - -// write either command or data, with automatic 4/8-bit selection -void LiquidCrystal::send(uint8_t value, uint8_t mode) { - digitalWrite(_rs_pin, mode); - - // if there is a RW pin indicated, set it low to Write - if (_rw_pin != 255) { - digitalWrite(_rw_pin, LOW); - } - - if (_displayfunction & LCD_8BITMODE) { - write8bits(value); - } else { - write4bits(value>>4); - write4bits(value); - } -} - -void LiquidCrystal::pulseEnable(void) { - digitalWrite(_enable_pin, LOW); - delayMicroseconds(1); - digitalWrite(_enable_pin, HIGH); - delayMicroseconds(1); // enable pulse must be >450ns - digitalWrite(_enable_pin, LOW); - delayMicroseconds(100); // commands need > 37us to settle -} - -void LiquidCrystal::write4bits(uint8_t value) { - for (int i = 0; i < 4; i++) { - pinMode(_data_pins[i], OUTPUT); - digitalWrite(_data_pins[i], (value >> i) & 0x01); - } - - pulseEnable(); -} - -void LiquidCrystal::write8bits(uint8_t value) { - for (int i = 0; i < 8; i++) { - pinMode(_data_pins[i], OUTPUT); - digitalWrite(_data_pins[i], (value >> i) & 0x01); - } - - pulseEnable(); -} diff --git a/LiquidCrystal.h b/LiquidCrystal.h deleted file mode 100755 index 24ec5af..0000000 --- a/LiquidCrystal.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef LiquidCrystal_h -#define LiquidCrystal_h - -#include -#include "Print.h" - -// commands -#define LCD_CLEARDISPLAY 0x01 -#define LCD_RETURNHOME 0x02 -#define LCD_ENTRYMODESET 0x04 -#define LCD_DISPLAYCONTROL 0x08 -#define LCD_CURSORSHIFT 0x10 -#define LCD_FUNCTIONSET 0x20 -#define LCD_SETCGRAMADDR 0x40 -#define LCD_SETDDRAMADDR 0x80 - -// flags for display entry mode -#define LCD_ENTRYRIGHT 0x00 -#define LCD_ENTRYLEFT 0x02 -#define LCD_ENTRYSHIFTINCREMENT 0x01 -#define LCD_ENTRYSHIFTDECREMENT 0x00 - -// flags for display on/off control -#define LCD_DISPLAYON 0x04 -#define LCD_DISPLAYOFF 0x00 -#define LCD_CURSORON 0x02 -#define LCD_CURSOROFF 0x00 -#define LCD_BLINKON 0x01 -#define LCD_BLINKOFF 0x00 - -// flags for display/cursor shift -#define LCD_DISPLAYMOVE 0x08 -#define LCD_CURSORMOVE 0x00 -#define LCD_MOVERIGHT 0x04 -#define LCD_MOVELEFT 0x00 - -// flags for function set -#define LCD_8BITMODE 0x10 -#define LCD_4BITMODE 0x00 -#define LCD_2LINE 0x08 -#define LCD_1LINE 0x00 -#define LCD_5x10DOTS 0x04 -#define LCD_5x8DOTS 0x00 - -class LiquidCrystal : public Print { -public: - LiquidCrystal(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(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(uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); - LiquidCrystal(uint8_t rs, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); - - void init(uint8_t fourbitmode, 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); - - void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); - - void clear(); - void home(); - - void noDisplay(); - void display(); - void noBlink(); - void blink(); - void noCursor(); - void cursor(); - void scrollDisplayLeft(); - void scrollDisplayRight(); - void leftToRight(); - void rightToLeft(); - void autoscroll(); - void noAutoscroll(); - - void createChar(uint8_t, uint8_t[]); - void setCursor(uint8_t, uint8_t); - virtual size_t write(uint8_t); - void command(uint8_t); - - using Print::write; -private: - void send(uint8_t, uint8_t); - void write4bits(uint8_t); - void write8bits(uint8_t); - void pulseEnable(); - - uint8_t _rs_pin; // LOW: command. HIGH: character. - uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. - uint8_t _enable_pin; // activated by a HIGH pulse. - uint8_t _data_pins[8]; - - uint8_t _displayfunction; - uint8_t _displaycontrol; - uint8_t _displaymode; - - uint8_t _initialized; - - uint8_t _numlines,_currline; -}; - -#endif diff --git a/examples/Autoscroll/Autoscroll.ino b/examples/Autoscroll/Autoscroll.ino deleted file mode 100644 index 27123ad..0000000 --- a/examples/Autoscroll/Autoscroll.ino +++ /dev/null @@ -1,73 +0,0 @@ -/* - LiquidCrystal Library - Autoscroll - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch demonstrates the use of the autoscroll() - and noAutoscroll() functions to make new text scroll or not. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16,2); -} - -void loop() { - // set the cursor to (0,0): - lcd.setCursor(0, 0); - // print from 0 to 9: - for (int thisChar = 0; thisChar < 10; thisChar++) { - lcd.print(thisChar); - delay(500); - } - - // set the cursor to (16,1): - lcd.setCursor(16,1); - // set the display to automatically scroll: - lcd.autoscroll(); - // print from 0 to 9: - for (int thisChar = 0; thisChar < 10; thisChar++) { - lcd.print(thisChar); - delay(500); - } - // turn off automatic scrolling - lcd.noAutoscroll(); - - // clear screen for the next loop: - lcd.clear(); -} - diff --git a/examples/Blink/Blink.ino b/examples/Blink/Blink.ino deleted file mode 100644 index e410424..0000000 --- a/examples/Blink/Blink.ino +++ /dev/null @@ -1,61 +0,0 @@ -/* - LiquidCrystal Library - Blink - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and makes the - cursor block blink. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - // Print a message to the LCD. - lcd.print("hello, world!"); -} - -void loop() { - // Turn off the blinking cursor: - lcd.noBlink(); - delay(3000); - // Turn on the blinking cursor: - lcd.blink(); - delay(3000); -} - - diff --git a/examples/Cursor/Cursor.ino b/examples/Cursor/Cursor.ino deleted file mode 100644 index 28e2a6a..0000000 --- a/examples/Cursor/Cursor.ino +++ /dev/null @@ -1,60 +0,0 @@ -/* - LiquidCrystal Library - Cursor - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and - uses the cursor() and noCursor() methods to turn - on and off the cursor. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - // Print a message to the LCD. - lcd.print("hello, world!"); -} - -void loop() { - // Turn off the cursor: - lcd.noCursor(); - delay(500); - // Turn on the cursor: - lcd.cursor(); - delay(500); -} - diff --git a/examples/CustomCharacter/CustomCharacter.ino b/examples/CustomCharacter/CustomCharacter.ino deleted file mode 100644 index d3ce479..0000000 --- a/examples/CustomCharacter/CustomCharacter.ino +++ /dev/null @@ -1,138 +0,0 @@ -/* - LiquidCrystal Library - Custom Characters - - Demonstrates how to add custom characters on an LCD display. - The LiquidCrystal library works with all LCD displays that are - compatible with the Hitachi HD44780 driver. There are many of - them out there, and you can usually tell them by the 16-pin interface. - - This sketch prints "I Arduino!" and a little dancing man - to the LCD. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K potentiometer: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - * 10K poterntiometer on pin A0 - - created21 Mar 2011 - by Tom Igoe - Based on Adafruit's example at - https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde - - This example code is in the public domain. - http://www.arduino.cc/en/Tutorial/LiquidCrystal - - Also useful: - http://icontexto.com/charactercreator/ - - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -// make some custom characters: -byte heart[8] = { - 0b00000, - 0b01010, - 0b11111, - 0b11111, - 0b11111, - 0b01110, - 0b00100, - 0b00000 -}; - -byte smiley[8] = { - 0b00000, - 0b00000, - 0b01010, - 0b00000, - 0b00000, - 0b10001, - 0b01110, - 0b00000 -}; - -byte frownie[8] = { - 0b00000, - 0b00000, - 0b01010, - 0b00000, - 0b00000, - 0b00000, - 0b01110, - 0b10001 -}; - -byte armsDown[8] = { - 0b00100, - 0b01010, - 0b00100, - 0b00100, - 0b01110, - 0b10101, - 0b00100, - 0b01010 -}; - -byte armsUp[8] = { - 0b00100, - 0b01010, - 0b00100, - 0b10101, - 0b01110, - 0b00100, - 0b00100, - 0b01010 -}; -void setup() { - // create a new character - lcd.createChar(0, heart); - // create a new character - lcd.createChar(1, smiley); - // create a new character - lcd.createChar(2, frownie); - // create a new character - lcd.createChar(3, armsDown); - // create a new character - lcd.createChar(4, armsUp); - - // set up the lcd's number of columns and rows: - lcd.begin(16, 2); - // Print a message to the lcd. - lcd.print("I "); - lcd.write(0); - lcd.print(" Arduino! "); - lcd.write(1); - -} - -void loop() { - // read the potentiometer on A0: - int sensorReading = analogRead(A0); - // map the result to 200 - 1000: - int delayTime = map(sensorReading, 0, 1023, 200, 1000); - // set the cursor to the bottom row, 5th position: - lcd.setCursor(4, 1); - // draw the little man, arms down: - lcd.write(3); - delay(delayTime); - lcd.setCursor(4, 1); - // draw him arms up: - lcd.write(4); - delay(delayTime); -} - - - diff --git a/examples/Display/Display.ino b/examples/Display/Display.ino deleted file mode 100644 index b000731..0000000 --- a/examples/Display/Display.ino +++ /dev/null @@ -1,60 +0,0 @@ -/* - LiquidCrystal Library - display() and noDisplay() - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and uses the - display() and noDisplay() functions to turn on and off - the display. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - // Print a message to the LCD. - lcd.print("hello, world!"); -} - -void loop() { - // Turn off the display: - lcd.noDisplay(); - delay(500); - // Turn on the display: - lcd.display(); - delay(500); -} - diff --git a/examples/HelloWorld/HelloWorld.ino b/examples/HelloWorld/HelloWorld.ino deleted file mode 100644 index e99957d..0000000 --- a/examples/HelloWorld/HelloWorld.ino +++ /dev/null @@ -1,58 +0,0 @@ -/* - LiquidCrystal Library - Hello World - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD - and shows the time. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - // Print a message to the LCD. - lcd.print("hello, world!"); -} - -void loop() { - // set the cursor to column 0, line 1 - // (note: line 1 is the second row, since counting begins with 0): - lcd.setCursor(0, 1); - // print the number of seconds since reset: - lcd.print(millis()/1000); -} - diff --git a/examples/Scroll/Scroll.ino b/examples/Scroll/Scroll.ino deleted file mode 100644 index 71e5e8c..0000000 --- a/examples/Scroll/Scroll.ino +++ /dev/null @@ -1,85 +0,0 @@ -/* - LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and uses the - scrollDisplayLeft() and scrollDisplayRight() methods to scroll - the text. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - // Print a message to the LCD. - lcd.print("hello, world!"); - delay(1000); -} - -void loop() { - // scroll 13 positions (string length) to the left - // to move it offscreen left: - for (int positionCounter = 0; positionCounter < 13; positionCounter++) { - // scroll one position left: - lcd.scrollDisplayLeft(); - // wait a bit: - delay(150); - } - - // scroll 29 positions (string length + display length) to the right - // to move it offscreen right: - for (int positionCounter = 0; positionCounter < 29; positionCounter++) { - // scroll one position right: - lcd.scrollDisplayRight(); - // wait a bit: - delay(150); - } - - // scroll 16 positions (display length + string length) to the left - // to move it back to center: - for (int positionCounter = 0; positionCounter < 16; positionCounter++) { - // scroll one position left: - lcd.scrollDisplayLeft(); - // wait a bit: - delay(150); - } - - // delay at the end of the full loop: - delay(1000); - -} - diff --git a/examples/SerialDisplay/SerialDisplay.ino b/examples/SerialDisplay/SerialDisplay.ino deleted file mode 100644 index 9727cee..0000000 --- a/examples/SerialDisplay/SerialDisplay.ino +++ /dev/null @@ -1,65 +0,0 @@ -/* - LiquidCrystal Library - Serial Input - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch displays text sent over the serial port - (e.g. from the Serial Monitor) on an attached LCD. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup(){ - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - // initialize the serial communications: - Serial.begin(9600); -} - -void loop() -{ - // when characters arrive over the serial port... - if (Serial.available()) { - // wait a bit for the entire message to arrive - delay(100); - // clear the screen - lcd.clear(); - // read all the available characters - while (Serial.available() > 0) { - // display each character to the LCD - lcd.write(Serial.read()); - } - } -} diff --git a/examples/TextDirection/TextDirection.ino b/examples/TextDirection/TextDirection.ino deleted file mode 100644 index 51bab1f..0000000 --- a/examples/TextDirection/TextDirection.ino +++ /dev/null @@ -1,87 +0,0 @@ - /* - LiquidCrystal Library - TextDirection - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch demonstrates how to use leftToRight() and rightToLeft() - to move the cursor. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - - */ - -// include the library code: -#include - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -int thisChar = 'a'; - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16, 2); - // turn on the cursor: - lcd.cursor(); - Serial.begin(9600); -} - -void loop() { - // reverse directions at 'm': - if (thisChar == 'm') { - // go right for the next letter - lcd.rightToLeft(); - } - // reverse again at 's': - if (thisChar == 's') { - // go left for the next letter - lcd.leftToRight(); - } - // reset at 'z': - if (thisChar > 'z') { - // go to (0,0): - lcd.home(); - // start again at 0 - thisChar = 'a'; - } - // print the character - lcd.write(thisChar); - // wait a second: - delay(1000); - // increment the letter: - thisChar++; -} - - - - - - - - diff --git a/examples/setCursor/setCursor.ino b/examples/setCursor/setCursor.ino deleted file mode 100644 index 3c4edf3..0000000 --- a/examples/setCursor/setCursor.ino +++ /dev/null @@ -1,71 +0,0 @@ -/* - LiquidCrystal Library - setCursor - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch prints to all the positions of the LCD using the - setCursor(0 method: - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://www.arduino.cc/en/Tutorial/LiquidCrystal - */ - -// include the library code: -#include - -// these constants won't change. But you can change the size of -// your LCD using them: -const int numRows = 2; -const int numCols = 16; - -// initialize the library with the numbers of the interface pins -LiquidCrystal lcd(12, 11, 5, 4, 3, 2); - -void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(numCols,numRows); -} - -void loop() { - // loop from ASCII 'a' to ASCII 'z': - for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { - // loop over the columns: - for (int thisCol = 0; thisCol < numRows; thisCol++) { - // loop over the rows: - for (int thisRow = 0; thisRow < numCols; thisRow++) { - // set the cursor position: - lcd.setCursor(thisRow,thisCol); - // print the letter: - lcd.write(thisLetter); - delay(200); - } - } - } -} - - diff --git a/keywords.txt b/keywords.txt deleted file mode 100755 index 132845c..0000000 --- a/keywords.txt +++ /dev/null @@ -1,37 +0,0 @@ -####################################### -# Syntax Coloring Map For LiquidCrystal -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -LiquidCrystal KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -begin KEYWORD2 -clear KEYWORD2 -home KEYWORD2 -print KEYWORD2 -setCursor KEYWORD2 -cursor KEYWORD2 -noCursor KEYWORD2 -blink KEYWORD2 -noBlink KEYWORD2 -display KEYWORD2 -noDisplay KEYWORD2 -autoscroll KEYWORD2 -noAutoscroll KEYWORD2 -leftToRight KEYWORD2 -rightToLeft KEYWORD2 -scrollDisplayLeft KEYWORD2 -scrollDisplayRight KEYWORD2 -createChar KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### - From b2cbc5eb4cc5142b932f4d20651b167ff37cfbd0 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 3 Sep 2012 16:13:28 +0200 Subject: [PATCH 02/19] LiquidCrystal library is already multiplatform compliant, moved into libraries folder --- LiquidCrystal.cpp | 310 +++++++++++++++++++ LiquidCrystal.h | 106 +++++++ examples/Autoscroll/Autoscroll.ino | 74 +++++ examples/Blink/Blink.ino | 61 ++++ examples/Cursor/Cursor.ino | 61 ++++ examples/CustomCharacter/CustomCharacter.ino | 138 +++++++++ examples/Display/Display.ino | 61 ++++ examples/HelloWorld/HelloWorld.ino | 58 ++++ examples/Scroll/Scroll.ino | 86 +++++ examples/SerialDisplay/SerialDisplay.ino | 65 ++++ examples/TextDirection/TextDirection.ino | 86 +++++ examples/setCursor/setCursor.ino | 72 +++++ keywords.txt | 37 +++ 13 files changed, 1215 insertions(+) create mode 100644 LiquidCrystal.cpp create mode 100755 LiquidCrystal.h create mode 100644 examples/Autoscroll/Autoscroll.ino create mode 100644 examples/Blink/Blink.ino create mode 100644 examples/Cursor/Cursor.ino create mode 100644 examples/CustomCharacter/CustomCharacter.ino create mode 100644 examples/Display/Display.ino create mode 100644 examples/HelloWorld/HelloWorld.ino create mode 100644 examples/Scroll/Scroll.ino create mode 100644 examples/SerialDisplay/SerialDisplay.ino create mode 100644 examples/TextDirection/TextDirection.ino create mode 100644 examples/setCursor/setCursor.ino create mode 100755 keywords.txt diff --git a/LiquidCrystal.cpp b/LiquidCrystal.cpp new file mode 100644 index 0000000..0653487 --- /dev/null +++ b/LiquidCrystal.cpp @@ -0,0 +1,310 @@ +#include "LiquidCrystal.h" + +#include +#include +#include +#include "Arduino.h" + +// When the display powers up, it is configured as follows: +// +// 1. Display clear +// 2. Function set: +// DL = 1; 8-bit interface data +// N = 0; 1-line display +// F = 0; 5x8 dot character font +// 3. Display on/off control: +// D = 0; Display off +// C = 0; Cursor off +// B = 0; Blinking off +// 4. Entry mode set: +// I/D = 1; Increment by 1 +// S = 0; No shift +// +// Note, however, that resetting the Arduino doesn't reset the LCD, so we +// can't assume that its in that state when a sketch starts (and the +// LiquidCrystal constructor is called). + +LiquidCrystal::LiquidCrystal(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) +{ + init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal::LiquidCrystal(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) +{ + init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +void LiquidCrystal::init(uint8_t fourbitmode, 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) +{ + _rs_pin = rs; + _rw_pin = rw; + _enable_pin = enable; + + _data_pins[0] = d0; + _data_pins[1] = d1; + _data_pins[2] = d2; + _data_pins[3] = d3; + _data_pins[4] = d4; + _data_pins[5] = d5; + _data_pins[6] = d6; + _data_pins[7] = d7; + + pinMode(_rs_pin, OUTPUT); + // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# + if (_rw_pin != 255) { + pinMode(_rw_pin, OUTPUT); + } + pinMode(_enable_pin, OUTPUT); + + if (fourbitmode) + _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; + else + _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; + + begin(16, 1); +} + +void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { + if (lines > 1) { + _displayfunction |= LCD_2LINE; + } + _numlines = lines; + _currline = 0; + + // for some 1 line displays you can select a 10 pixel high font + if ((dotsize != 0) && (lines == 1)) { + _displayfunction |= LCD_5x10DOTS; + } + + // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + // according to datasheet, we need at least 40ms after power rises above 2.7V + // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 + delayMicroseconds(50000); + // Now we pull both RS and R/W low to begin commands + digitalWrite(_rs_pin, LOW); + digitalWrite(_enable_pin, LOW); + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + //put the LCD into 4 bit or 8 bit mode + if (! (_displayfunction & LCD_8BITMODE)) { + // this is according to the hitachi HD44780 datasheet + // figure 24, pg 46 + + // we start in 8bit mode, try to set 4 bit mode + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // second try + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // third go! + write4bits(0x03); + delayMicroseconds(150); + + // finally, set to 4-bit interface + write4bits(0x02); + } else { + // this is according to the hitachi HD44780 datasheet + // page 45 figure 23 + + // Send function set command sequence + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(4500); // wait more than 4.1ms + + // second try + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(150); + + // third go + command(LCD_FUNCTIONSET | _displayfunction); + } + + // finally, set # lines, font size, etc. + command(LCD_FUNCTIONSET | _displayfunction); + + // turn the display on with no cursor or blinking default + _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + display(); + + // clear it off + clear(); + + // Initialize to default text direction (for romance languages) + _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; + // set the entry mode + command(LCD_ENTRYMODESET | _displaymode); + +} + +/********** high level commands, for the user! */ +void LiquidCrystal::clear() +{ + command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal::home() +{ + command(LCD_RETURNHOME); // set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal::setCursor(uint8_t col, uint8_t row) +{ + int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + if ( row >= _numlines ) { + row = _numlines-1; // we count rows starting w/0 + } + + command(LCD_SETDDRAMADDR | (col + row_offsets[row])); +} + +// Turn the display on/off (quickly) +void LiquidCrystal::noDisplay() { + _displaycontrol &= ~LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::display() { + _displaycontrol |= LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turns the underline cursor on/off +void LiquidCrystal::noCursor() { + _displaycontrol &= ~LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::cursor() { + _displaycontrol |= LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turn on and off the blinking cursor +void LiquidCrystal::noBlink() { + _displaycontrol &= ~LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::blink() { + _displaycontrol |= LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// These commands scroll the display without changing the RAM +void LiquidCrystal::scrollDisplayLeft(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); +} +void LiquidCrystal::scrollDisplayRight(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); +} + +// This is for text that flows Left to Right +void LiquidCrystal::leftToRight(void) { + _displaymode |= LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This is for text that flows Right to Left +void LiquidCrystal::rightToLeft(void) { + _displaymode &= ~LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'right justify' text from the cursor +void LiquidCrystal::autoscroll(void) { + _displaymode |= LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'left justify' text from the cursor +void LiquidCrystal::noAutoscroll(void) { + _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// Allows us to fill the first 8 CGRAM locations +// with custom characters +void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) { + location &= 0x7; // we only have 8 locations 0-7 + command(LCD_SETCGRAMADDR | (location << 3)); + for (int i=0; i<8; i++) { + write(charmap[i]); + } +} + +/*********** mid level commands, for sending data/cmds */ + +inline void LiquidCrystal::command(uint8_t value) { + send(value, LOW); +} + +inline size_t LiquidCrystal::write(uint8_t value) { + send(value, HIGH); + return 1; // assume sucess +} + +/************ low level data pushing commands **********/ + +// write either command or data, with automatic 4/8-bit selection +void LiquidCrystal::send(uint8_t value, uint8_t mode) { + digitalWrite(_rs_pin, mode); + + // if there is a RW pin indicated, set it low to Write + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + if (_displayfunction & LCD_8BITMODE) { + write8bits(value); + } else { + write4bits(value>>4); + write4bits(value); + } +} + +void LiquidCrystal::pulseEnable(void) { + digitalWrite(_enable_pin, LOW); + delayMicroseconds(1); + digitalWrite(_enable_pin, HIGH); + delayMicroseconds(1); // enable pulse must be >450ns + digitalWrite(_enable_pin, LOW); + delayMicroseconds(100); // commands need > 37us to settle +} + +void LiquidCrystal::write4bits(uint8_t value) { + for (int i = 0; i < 4; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} + +void LiquidCrystal::write8bits(uint8_t value) { + for (int i = 0; i < 8; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} diff --git a/LiquidCrystal.h b/LiquidCrystal.h new file mode 100755 index 0000000..24ec5af --- /dev/null +++ b/LiquidCrystal.h @@ -0,0 +1,106 @@ +#ifndef LiquidCrystal_h +#define LiquidCrystal_h + +#include +#include "Print.h" + +// commands +#define LCD_CLEARDISPLAY 0x01 +#define LCD_RETURNHOME 0x02 +#define LCD_ENTRYMODESET 0x04 +#define LCD_DISPLAYCONTROL 0x08 +#define LCD_CURSORSHIFT 0x10 +#define LCD_FUNCTIONSET 0x20 +#define LCD_SETCGRAMADDR 0x40 +#define LCD_SETDDRAMADDR 0x80 + +// flags for display entry mode +#define LCD_ENTRYRIGHT 0x00 +#define LCD_ENTRYLEFT 0x02 +#define LCD_ENTRYSHIFTINCREMENT 0x01 +#define LCD_ENTRYSHIFTDECREMENT 0x00 + +// flags for display on/off control +#define LCD_DISPLAYON 0x04 +#define LCD_DISPLAYOFF 0x00 +#define LCD_CURSORON 0x02 +#define LCD_CURSOROFF 0x00 +#define LCD_BLINKON 0x01 +#define LCD_BLINKOFF 0x00 + +// flags for display/cursor shift +#define LCD_DISPLAYMOVE 0x08 +#define LCD_CURSORMOVE 0x00 +#define LCD_MOVERIGHT 0x04 +#define LCD_MOVELEFT 0x00 + +// flags for function set +#define LCD_8BITMODE 0x10 +#define LCD_4BITMODE 0x00 +#define LCD_2LINE 0x08 +#define LCD_1LINE 0x00 +#define LCD_5x10DOTS 0x04 +#define LCD_5x8DOTS 0x00 + +class LiquidCrystal : public Print { +public: + LiquidCrystal(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(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(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + + void init(uint8_t fourbitmode, 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); + + void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); + + void clear(); + void home(); + + void noDisplay(); + void display(); + void noBlink(); + void blink(); + void noCursor(); + void cursor(); + void scrollDisplayLeft(); + void scrollDisplayRight(); + void leftToRight(); + void rightToLeft(); + void autoscroll(); + void noAutoscroll(); + + void createChar(uint8_t, uint8_t[]); + void setCursor(uint8_t, uint8_t); + virtual size_t write(uint8_t); + void command(uint8_t); + + using Print::write; +private: + void send(uint8_t, uint8_t); + void write4bits(uint8_t); + void write8bits(uint8_t); + void pulseEnable(); + + uint8_t _rs_pin; // LOW: command. HIGH: character. + uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. + uint8_t _enable_pin; // activated by a HIGH pulse. + uint8_t _data_pins[8]; + + uint8_t _displayfunction; + uint8_t _displaycontrol; + uint8_t _displaymode; + + uint8_t _initialized; + + uint8_t _numlines,_currline; +}; + +#endif diff --git a/examples/Autoscroll/Autoscroll.ino b/examples/Autoscroll/Autoscroll.ino new file mode 100644 index 0000000..1127d8f --- /dev/null +++ b/examples/Autoscroll/Autoscroll.ino @@ -0,0 +1,74 @@ +/* + LiquidCrystal Library - Autoscroll + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates the use of the autoscroll() + and noAutoscroll() functions to make new text scroll or not. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16,2); +} + +void loop() { + // set the cursor to (0,0): + lcd.setCursor(0, 0); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + + // set the cursor to (16,1): + lcd.setCursor(16,1); + // set the display to automatically scroll: + lcd.autoscroll(); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + // turn off automatic scrolling + lcd.noAutoscroll(); + + // clear screen for the next loop: + lcd.clear(); +} + diff --git a/examples/Blink/Blink.ino b/examples/Blink/Blink.ino new file mode 100644 index 0000000..9667b5d --- /dev/null +++ b/examples/Blink/Blink.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal Library - Blink + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and makes the + cursor block blink. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalBlink + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the blinking cursor: + lcd.noBlink(); + delay(3000); + // Turn on the blinking cursor: + lcd.blink(); + delay(3000); +} + + diff --git a/examples/Cursor/Cursor.ino b/examples/Cursor/Cursor.ino new file mode 100644 index 0000000..05862a4 --- /dev/null +++ b/examples/Cursor/Cursor.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal Library - Cursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and + uses the cursor() and noCursor() methods to turn + on and off the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalCursor + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the cursor: + lcd.noCursor(); + delay(500); + // Turn on the cursor: + lcd.cursor(); + delay(500); +} + diff --git a/examples/CustomCharacter/CustomCharacter.ino b/examples/CustomCharacter/CustomCharacter.ino new file mode 100644 index 0000000..d3ce479 --- /dev/null +++ b/examples/CustomCharacter/CustomCharacter.ino @@ -0,0 +1,138 @@ +/* + LiquidCrystal Library - Custom Characters + + Demonstrates how to add custom characters on an LCD display. + The LiquidCrystal library works with all LCD displays that are + compatible with the Hitachi HD44780 driver. There are many of + them out there, and you can usually tell them by the 16-pin interface. + + This sketch prints "I Arduino!" and a little dancing man + to the LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + * 10K poterntiometer on pin A0 + + created21 Mar 2011 + by Tom Igoe + Based on Adafruit's example at + https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystal + + Also useful: + http://icontexto.com/charactercreator/ + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +// make some custom characters: +byte heart[8] = { + 0b00000, + 0b01010, + 0b11111, + 0b11111, + 0b11111, + 0b01110, + 0b00100, + 0b00000 +}; + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +byte armsDown[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b00100, + 0b01110, + 0b10101, + 0b00100, + 0b01010 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; +void setup() { + // create a new character + lcd.createChar(0, heart); + // create a new character + lcd.createChar(1, smiley); + // create a new character + lcd.createChar(2, frownie); + // create a new character + lcd.createChar(3, armsDown); + // create a new character + lcd.createChar(4, armsUp); + + // set up the lcd's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the lcd. + lcd.print("I "); + lcd.write(0); + lcd.print(" Arduino! "); + lcd.write(1); + +} + +void loop() { + // read the potentiometer on A0: + int sensorReading = analogRead(A0); + // map the result to 200 - 1000: + int delayTime = map(sensorReading, 0, 1023, 200, 1000); + // set the cursor to the bottom row, 5th position: + lcd.setCursor(4, 1); + // draw the little man, arms down: + lcd.write(3); + delay(delayTime); + lcd.setCursor(4, 1); + // draw him arms up: + lcd.write(4); + delay(delayTime); +} + + + diff --git a/examples/Display/Display.ino b/examples/Display/Display.ino new file mode 100644 index 0000000..a85effb --- /dev/null +++ b/examples/Display/Display.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal Library - display() and noDisplay() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + display() and noDisplay() functions to turn on and off + the display. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalDisplay + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the display: + lcd.noDisplay(); + delay(500); + // Turn on the display: + lcd.display(); + delay(500); +} + diff --git a/examples/HelloWorld/HelloWorld.ino b/examples/HelloWorld/HelloWorld.ino new file mode 100644 index 0000000..e99957d --- /dev/null +++ b/examples/HelloWorld/HelloWorld.ino @@ -0,0 +1,58 @@ +/* + LiquidCrystal Library - Hello World + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD + and shows the time. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis()/1000); +} + diff --git a/examples/Scroll/Scroll.ino b/examples/Scroll/Scroll.ino new file mode 100644 index 0000000..0d6d8dc --- /dev/null +++ b/examples/Scroll/Scroll.ino @@ -0,0 +1,86 @@ +/* + LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalScroll + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); + delay(1000); +} + +void loop() { + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (int positionCounter = 0; positionCounter < 13; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (int positionCounter = 0; positionCounter < 29; positionCounter++) { + // scroll one position right: + lcd.scrollDisplayRight(); + // wait a bit: + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (int positionCounter = 0; positionCounter < 16; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // delay at the end of the full loop: + delay(1000); + +} + diff --git a/examples/SerialDisplay/SerialDisplay.ino b/examples/SerialDisplay/SerialDisplay.ino new file mode 100644 index 0000000..a6f8f40 --- /dev/null +++ b/examples/SerialDisplay/SerialDisplay.ino @@ -0,0 +1,65 @@ +/* + LiquidCrystal Library - Serial Input + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch displays text sent over the serial port + (e.g. from the Serial Monitor) on an attached LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalSerial + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup(){ + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // initialize the serial communications: + Serial.begin(9600); +} + +void loop() +{ + // when characters arrive over the serial port... + if (Serial.available()) { + // wait a bit for the entire message to arrive + delay(100); + // clear the screen + lcd.clear(); + // read all the available characters + while (Serial.available() > 0) { + // display each character to the LCD + lcd.write(Serial.read()); + } + } +} diff --git a/examples/TextDirection/TextDirection.ino b/examples/TextDirection/TextDirection.ino new file mode 100644 index 0000000..cabd8ea --- /dev/null +++ b/examples/TextDirection/TextDirection.ino @@ -0,0 +1,86 @@ + /* + LiquidCrystal Library - TextDirection + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates how to use leftToRight() and rightToLeft() + to move the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +int thisChar = 'a'; + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // turn on the cursor: + lcd.cursor(); +} + +void loop() { + // reverse directions at 'm': + if (thisChar == 'm') { + // go right for the next letter + lcd.rightToLeft(); + } + // reverse again at 's': + if (thisChar == 's') { + // go left for the next letter + lcd.leftToRight(); + } + // reset at 'z': + if (thisChar > 'z') { + // go to (0,0): + lcd.home(); + // start again at 0 + thisChar = 'a'; + } + // print the character + lcd.write(thisChar); + // wait a second: + delay(1000); + // increment the letter: + thisChar++; +} + + + + + + + + diff --git a/examples/setCursor/setCursor.ino b/examples/setCursor/setCursor.ino new file mode 100644 index 0000000..e45c491 --- /dev/null +++ b/examples/setCursor/setCursor.ino @@ -0,0 +1,72 @@ +/* + LiquidCrystal Library - setCursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints to all the positions of the LCD using the + setCursor(0 method: + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor + + */ + +// include the library code: +#include + +// these constants won't change. But you can change the size of +// your LCD using them: +const int numRows = 2; +const int numCols = 16; + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(numCols,numRows); +} + +void loop() { + // loop from ASCII 'a' to ASCII 'z': + for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { + // loop over the columns: + for (int thisCol = 0; thisCol < numRows; thisCol++) { + // loop over the rows: + for (int thisRow = 0; thisRow < numCols; thisRow++) { + // set the cursor position: + lcd.setCursor(thisRow,thisCol); + // print the letter: + lcd.write(thisLetter); + delay(200); + } + } + } +} + + diff --git a/keywords.txt b/keywords.txt new file mode 100755 index 0000000..132845c --- /dev/null +++ b/keywords.txt @@ -0,0 +1,37 @@ +####################################### +# Syntax Coloring Map For LiquidCrystal +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +LiquidCrystal KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +clear KEYWORD2 +home KEYWORD2 +print KEYWORD2 +setCursor KEYWORD2 +cursor KEYWORD2 +noCursor KEYWORD2 +blink KEYWORD2 +noBlink KEYWORD2 +display KEYWORD2 +noDisplay KEYWORD2 +autoscroll KEYWORD2 +noAutoscroll KEYWORD2 +leftToRight KEYWORD2 +rightToLeft KEYWORD2 +scrollDisplayLeft KEYWORD2 +scrollDisplayRight KEYWORD2 +createChar KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + From 29ed8df7e5bfe522c9e92e3885e0242403c3dde8 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Wed, 5 Dec 2012 15:35:41 +0100 Subject: [PATCH 03/19] fixed permissions on a lot of text files. see #1116 --- LiquidCrystal.h | 0 keywords.txt | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 LiquidCrystal.h mode change 100755 => 100644 keywords.txt diff --git a/LiquidCrystal.h b/LiquidCrystal.h old mode 100755 new mode 100644 diff --git a/keywords.txt b/keywords.txt old mode 100755 new mode 100644 From c40724514c1d72d2dabf56b26a7fca16bd90e437 Mon Sep 17 00:00:00 2001 From: Fede85 Date: Wed, 26 Jun 2013 19:13:04 +0200 Subject: [PATCH 04/19] Ethernet, SD and LiquidCrystal to the new library format --- library.properties | 10 ++++++++++ LiquidCrystal.cpp => src/LiquidCrystal.cpp | 0 LiquidCrystal.h => src/LiquidCrystal.h | 0 3 files changed, 10 insertions(+) create mode 100644 library.properties rename LiquidCrystal.cpp => src/LiquidCrystal.cpp (100%) rename LiquidCrystal.h => src/LiquidCrystal.h (100%) diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..2fc0606 --- /dev/null +++ b/library.properties @@ -0,0 +1,10 @@ +name=LiquidCrystal +author= +email=info@arduino.cc +sentence=The library to write on an alphanumeric LCD display. +paragraph=This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4- or 8-bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines). +url=http://arduino.cc/en/Reference/LiquidCrystal +architectures=avr, sam +version=1.0 +dependencies= none +core-dependencies=arduino (>=1.5.0) diff --git a/LiquidCrystal.cpp b/src/LiquidCrystal.cpp similarity index 100% rename from LiquidCrystal.cpp rename to src/LiquidCrystal.cpp diff --git a/LiquidCrystal.h b/src/LiquidCrystal.h similarity index 100% rename from LiquidCrystal.h rename to src/LiquidCrystal.h From 998f9ce164c317fa954464b4309637ee57168360 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 8 Aug 2013 16:40:55 +0200 Subject: [PATCH 05/19] Updated libraries metadata --- library.properties | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library.properties b/library.properties index 2fc0606..d67278b 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=LiquidCrystal author= -email=info@arduino.cc -sentence=The library to write on an alphanumeric LCD display. -paragraph=This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4- or 8-bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines). +email= +sentence=Write to an alphanumeric LCD display. +paragraph=This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4 or 8 bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines). url=http://arduino.cc/en/Reference/LiquidCrystal -architectures=avr, sam +architectures=* version=1.0 -dependencies= none +dependencies= core-dependencies=arduino (>=1.5.0) From e0a449386898d0268259b272c7d4d2651204396f Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 21 Oct 2013 09:58:40 +0200 Subject: [PATCH 06/19] Run new astyle formatter against all the examples --- examples/Autoscroll/Autoscroll.ino | 26 +++---- examples/Blink/Blink.ino | 22 +++--- examples/Cursor/Cursor.ino | 16 ++-- examples/CustomCharacter/CustomCharacter.ino | 30 +++---- examples/Display/Display.ino | 18 ++--- examples/HelloWorld/HelloWorld.ino | 16 ++-- examples/Scroll/Scroll.ino | 34 ++++---- examples/SerialDisplay/SerialDisplay.ino | 22 +++--- examples/TextDirection/TextDirection.ino | 82 ++++++++++---------- examples/setCursor/setCursor.ino | 22 +++--- 10 files changed, 144 insertions(+), 144 deletions(-) diff --git a/examples/Autoscroll/Autoscroll.ino b/examples/Autoscroll/Autoscroll.ino index 1127d8f..0acb3af 100644 --- a/examples/Autoscroll/Autoscroll.ino +++ b/examples/Autoscroll/Autoscroll.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Autoscroll - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch demonstrates the use of the autoscroll() and noAutoscroll() functions to make new text scroll or not. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,16 +20,16 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll @@ -43,8 +43,8 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(16,2); + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); } void loop() { @@ -52,12 +52,12 @@ void loop() { lcd.setCursor(0, 0); // print from 0 to 9: for (int thisChar = 0; thisChar < 10; thisChar++) { - lcd.print(thisChar); - delay(500); + 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(); // print from 0 to 9: @@ -67,7 +67,7 @@ void loop() { } // turn off automatic scrolling lcd.noAutoscroll(); - + // clear screen for the next loop: lcd.clear(); } diff --git a/examples/Blink/Blink.ino b/examples/Blink/Blink.ino index 9667b5d..856d522 100644 --- a/examples/Blink/Blink.ino +++ b/examples/Blink/Blink.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Blink - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and makes the + + This sketch prints "Hello World!" to the LCD and makes the cursor block blink. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,20 +20,20 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. http://arduino.cc/en/Tutorial/LiquidCrystalBlink - + */ // include the library code: @@ -43,7 +43,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -53,7 +53,7 @@ void loop() { // Turn off the blinking cursor: lcd.noBlink(); delay(3000); - // Turn on the blinking cursor: + // Turn on the blinking cursor: lcd.blink(); delay(3000); } diff --git a/examples/Cursor/Cursor.ino b/examples/Cursor/Cursor.ino index 05862a4..5f68d91 100644 --- a/examples/Cursor/Cursor.ino +++ b/examples/Cursor/Cursor.ino @@ -1,15 +1,15 @@ /* LiquidCrystal Library - Cursor - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "Hello World!" to the LCD and uses the cursor() and noCursor() methods to turn on and off the cursor. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,13 +21,13 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe @@ -44,7 +44,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -54,7 +54,7 @@ void loop() { // Turn off the cursor: lcd.noCursor(); delay(500); - // Turn on the cursor: + // Turn on the cursor: lcd.cursor(); delay(500); } diff --git a/examples/CustomCharacter/CustomCharacter.ino b/examples/CustomCharacter/CustomCharacter.ino index d3ce479..3a96488 100644 --- a/examples/CustomCharacter/CustomCharacter.ino +++ b/examples/CustomCharacter/CustomCharacter.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Custom Characters - - Demonstrates how to add custom characters on an LCD display. - The LiquidCrystal library works with all LCD displays that are - compatible with the Hitachi HD44780 driver. There are many of + + Demonstrates how to add custom characters on an LCD display. + The LiquidCrystal library works with all LCD displays that are + compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "I Arduino!" and a little dancing man to the LCD. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,18 +21,18 @@ * ends to +5V and ground * wiper to LCD VO pin (pin 3) * 10K poterntiometer on pin A0 - + created21 Mar 2011 by Tom Igoe Based on Adafruit's example at https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde - + This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystal - + Also useful: http://icontexto.com/charactercreator/ - + */ // include the library code: @@ -104,14 +104,14 @@ void setup() { // create a new character lcd.createChar(2, frownie); // create a new character - lcd.createChar(3, armsDown); + lcd.createChar(3, armsDown); // create a new character - lcd.createChar(4, armsUp); + lcd.createChar(4, armsUp); - // set up the lcd's number of columns and rows: + // set up the lcd's number of columns and rows: lcd.begin(16, 2); // Print a message to the lcd. - lcd.print("I "); + lcd.print("I "); lcd.write(0); lcd.print(" Arduino! "); lcd.write(1); @@ -131,7 +131,7 @@ void loop() { lcd.setCursor(4, 1); // draw him arms up: lcd.write(4); - delay(delayTime); + delay(delayTime); } diff --git a/examples/Display/Display.ino b/examples/Display/Display.ino index a85effb..5c9e67c 100644 --- a/examples/Display/Display.ino +++ b/examples/Display/Display.ino @@ -1,15 +1,15 @@ /* LiquidCrystal Library - display() and noDisplay() - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - - This sketch prints "Hello World!" to the LCD and uses the + + This sketch prints "Hello World!" to the LCD and uses the display() and noDisplay() functions to turn on and off the display. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,13 +21,13 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe @@ -44,7 +44,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -54,7 +54,7 @@ void loop() { // Turn off the display: lcd.noDisplay(); delay(500); - // Turn on the display: + // Turn on the display: lcd.display(); delay(500); } diff --git a/examples/HelloWorld/HelloWorld.ino b/examples/HelloWorld/HelloWorld.ino index e99957d..ec495b3 100644 --- a/examples/HelloWorld/HelloWorld.ino +++ b/examples/HelloWorld/HelloWorld.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Hello World - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "Hello World!" to the LCD and shows the time. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,7 +20,7 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 @@ -29,7 +29,7 @@ by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystal @@ -42,7 +42,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -53,6 +53,6 @@ void loop() { // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: - lcd.print(millis()/1000); + lcd.print(millis() / 1000); } diff --git a/examples/Scroll/Scroll.ino b/examples/Scroll/Scroll.ino index 0d6d8dc..3e44791 100644 --- a/examples/Scroll/Scroll.ino +++ b/examples/Scroll/Scroll.ino @@ -1,15 +1,15 @@ /* LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints "Hello World!" to the LCD and uses the scrollDisplayLeft() and scrollDisplayRight() methods to scroll the text. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -21,18 +21,18 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/LiquidCrystalScroll */ @@ -44,7 +44,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // Print a message to the LCD. lcd.print("hello, world!"); @@ -52,11 +52,11 @@ void setup() { } void loop() { - // scroll 13 positions (string length) to the left + // scroll 13 positions (string length) to the left // to move it offscreen left: for (int positionCounter = 0; positionCounter < 13; positionCounter++) { // scroll one position left: - lcd.scrollDisplayLeft(); + lcd.scrollDisplayLeft(); // wait a bit: delay(150); } @@ -65,20 +65,20 @@ void loop() { // to move it offscreen right: for (int positionCounter = 0; positionCounter < 29; positionCounter++) { // scroll one position right: - lcd.scrollDisplayRight(); + lcd.scrollDisplayRight(); // wait a bit: delay(150); } - - // scroll 16 positions (display length + string length) to the left - // to move it back to center: + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: for (int positionCounter = 0; positionCounter < 16; positionCounter++) { // scroll one position left: - lcd.scrollDisplayLeft(); + lcd.scrollDisplayLeft(); // wait a bit: delay(150); } - + // delay at the end of the full loop: delay(1000); diff --git a/examples/SerialDisplay/SerialDisplay.ino b/examples/SerialDisplay/SerialDisplay.ino index a6f8f40..5838dc5 100644 --- a/examples/SerialDisplay/SerialDisplay.ino +++ b/examples/SerialDisplay/SerialDisplay.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - Serial Input - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - - This sketch displays text sent over the serial port + + This sketch displays text sent over the serial port (e.g. from the Serial Monitor) on an attached LCD. - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,18 +20,18 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/LiquidCrystalSerial */ @@ -41,8 +41,8 @@ // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); -void setup(){ - // set up the LCD's number of columns and rows: +void setup() { + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // initialize the serial communications: Serial.begin(9600); diff --git a/examples/TextDirection/TextDirection.ino b/examples/TextDirection/TextDirection.ino index cabd8ea..3bb8695 100644 --- a/examples/TextDirection/TextDirection.ino +++ b/examples/TextDirection/TextDirection.ino @@ -1,40 +1,40 @@ - /* - LiquidCrystal Library - TextDirection - - Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the - Hitachi HD44780 driver. There are many of them out there, and you - can usually tell them by the 16-pin interface. - - This sketch demonstrates how to use leftToRight() and rightToLeft() - to move the cursor. - - The circuit: - * LCD RS pin to digital pin 12 - * LCD Enable pin to digital pin 11 - * LCD D4 pin to digital pin 5 - * LCD D5 pin to digital pin 4 - * LCD D6 pin to digital pin 3 - * LCD D7 pin to digital pin 2 - * LCD R/W pin to ground - * 10K resistor: - * ends to +5V and ground - * wiper to LCD VO pin (pin 3) - - Library originally added 18 Apr 2008 - by David A. Mellis - library modified 5 Jul 2009 - by Limor Fried (http://www.ladyada.net) - example added 9 Jul 2009 - by Tom Igoe - modified 22 Nov 2010 - by Tom Igoe - - This example code is in the public domain. - - http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection - - */ +/* +LiquidCrystal Library - TextDirection + +Demonstrates the use a 16x2 LCD display. The LiquidCrystal +library works with all LCD displays that are compatible with the +Hitachi HD44780 driver. There are many of them out there, and you +can usually tell them by the 16-pin interface. + +This sketch demonstrates how to use leftToRight() and rightToLeft() +to move the cursor. + +The circuit: +* LCD RS pin to digital pin 12 +* LCD Enable pin to digital pin 11 +* LCD D4 pin to digital pin 5 +* LCD D5 pin to digital pin 4 +* LCD D6 pin to digital pin 3 +* LCD D7 pin to digital pin 2 +* LCD R/W pin to ground +* 10K resistor: +* ends to +5V and ground +* wiper to LCD VO pin (pin 3) + +Library originally added 18 Apr 2008 +by David A. Mellis +library modified 5 Jul 2009 +by Limor Fried (http://www.ladyada.net) +example added 9 Jul 2009 +by Tom Igoe +modified 22 Nov 2010 +by Tom Igoe + +This example code is in the public domain. + +http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection + +*/ // include the library code: #include @@ -45,7 +45,7 @@ LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int thisChar = 'a'; void setup() { - // set up the LCD's number of columns and rows: + // set up the LCD's number of columns and rows: lcd.begin(16, 2); // turn on the cursor: lcd.cursor(); @@ -55,17 +55,17 @@ void loop() { // reverse directions at 'm': if (thisChar == 'm') { // go right for the next letter - lcd.rightToLeft(); + lcd.rightToLeft(); } // reverse again at 's': if (thisChar == 's') { // go left for the next letter - lcd.leftToRight(); + lcd.leftToRight(); } // reset at 'z': if (thisChar > 'z') { // go to (0,0): - lcd.home(); + lcd.home(); // start again at 0 thisChar = 'a'; } diff --git a/examples/setCursor/setCursor.ino b/examples/setCursor/setCursor.ino index e45c491..689f329 100644 --- a/examples/setCursor/setCursor.ino +++ b/examples/setCursor/setCursor.ino @@ -1,14 +1,14 @@ /* LiquidCrystal Library - setCursor - + Demonstrates the use a 16x2 LCD display. The LiquidCrystal - library works with all LCD displays that are compatible with the + library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. - + This sketch prints to all the positions of the LCD using the setCursor(0 method: - + The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 @@ -20,18 +20,18 @@ * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) - + Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 - by Tom Igoe + by Tom Igoe modified 22 Nov 2010 by Tom Igoe - + This example code is in the public domain. - + http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor */ @@ -48,8 +48,8 @@ const int numCols = 16; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() { - // set up the LCD's number of columns and rows: - lcd.begin(numCols,numRows); + // set up the LCD's number of columns and rows: + lcd.begin(numCols, numRows); } void loop() { @@ -60,7 +60,7 @@ void loop() { // loop over the rows: for (int thisRow = 0; thisRow < numCols; thisRow++) { // set the cursor position: - lcd.setCursor(thisRow,thisCol); + lcd.setCursor(thisRow, thisCol); // print the letter: lcd.write(thisLetter); delay(200); From 40fd0b306ace8da737914efdefc58ba2a8328b53 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 21 Oct 2013 13:16:51 +0200 Subject: [PATCH 07/19] Fixed compilation errors with some examples --- examples/CustomCharacter/CustomCharacter.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/CustomCharacter/CustomCharacter.ino b/examples/CustomCharacter/CustomCharacter.ino index 3a96488..233cad1 100644 --- a/examples/CustomCharacter/CustomCharacter.ino +++ b/examples/CustomCharacter/CustomCharacter.ino @@ -112,9 +112,9 @@ void setup() { lcd.begin(16, 2); // Print a message to the lcd. lcd.print("I "); - lcd.write(0); + lcd.write((byte) 0); lcd.print(" Arduino! "); - lcd.write(1); + lcd.write((byte) 1); } From 138bcb17c39aa662166a74abab76e9a9023d416e Mon Sep 17 00:00:00 2001 From: Mark Sproul Date: Sun, 4 Dec 2011 16:54:32 -0500 Subject: [PATCH 08/19] Added setRowOffsets to LiquidCrystal library Original commit by Mark Sproul, but cleaned up by Matthijs Kooijman. --- src/LiquidCrystal.cpp | 15 ++++++++++++--- src/LiquidCrystal.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/LiquidCrystal.cpp b/src/LiquidCrystal.cpp index 0653487..5dbb830 100644 --- a/src/LiquidCrystal.cpp +++ b/src/LiquidCrystal.cpp @@ -79,6 +79,8 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; + setRowOffsets(0x00, 0x40, 0x14, 0x54); + begin(16, 1); } @@ -157,6 +159,14 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { } +void LiquidCrystal::setRowOffsets(int row0, int row1, int row2, int row3) +{ + _row_offsets[0] = row0; + _row_offsets[1] = row1; + _row_offsets[2] = row2; + _row_offsets[3] = row3; +} + /********** high level commands, for the user! */ void LiquidCrystal::clear() { @@ -172,12 +182,11 @@ void LiquidCrystal::home() void LiquidCrystal::setCursor(uint8_t col, uint8_t row) { - int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; if ( row >= _numlines ) { - row = _numlines-1; // we count rows starting w/0 + row = _numlines - 1; // we count rows starting w/0 } - command(LCD_SETDDRAMADDR | (col + row_offsets[row])); + command(LCD_SETDDRAMADDR | (col + _row_offsets[row])); } // Turn the display on/off (quickly) diff --git a/src/LiquidCrystal.h b/src/LiquidCrystal.h index 24ec5af..1c0fa4f 100644 --- a/src/LiquidCrystal.h +++ b/src/LiquidCrystal.h @@ -77,6 +77,7 @@ public: void autoscroll(); void noAutoscroll(); + void setRowOffsets(int row1, int row2, int row3, int row4); void createChar(uint8_t, uint8_t[]); void setCursor(uint8_t, uint8_t); virtual size_t write(uint8_t); @@ -101,6 +102,7 @@ private: uint8_t _initialized; uint8_t _numlines,_currline; + int _row_offsets[4]; }; #endif From cb0c50909fcfaa39a1830d3c8f6c662cfaf22bf1 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 18 Dec 2013 12:37:01 +0100 Subject: [PATCH 09/19] Make the LiquidCrystal row offsets uint8_t instead of int Since these are memory addresses, there is no need to make them signed. Furthermore, the HD44780 chip supports memory addresses up to 0x67, so uint8_t shouldbe sufficient. --- src/LiquidCrystal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiquidCrystal.h b/src/LiquidCrystal.h index 1c0fa4f..684a65f 100644 --- a/src/LiquidCrystal.h +++ b/src/LiquidCrystal.h @@ -102,7 +102,7 @@ private: uint8_t _initialized; uint8_t _numlines,_currline; - int _row_offsets[4]; + uint8_t _row_offsets[4]; }; #endif From beed8515f711ccb541642ac1f6e2f7ef4393f67b Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 18 Dec 2013 12:34:44 +0100 Subject: [PATCH 10/19] In LiquidCrystal::setCursor(), check against length of _row_offsets as well Before, the row value was maximized against _numlines already, but the value from _numlines is not limited anywhere, so it could be longer than the length of _row_offsets. This check makes sure the array bounds is never exceeded. --- src/LiquidCrystal.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/LiquidCrystal.cpp b/src/LiquidCrystal.cpp index 5dbb830..27b5377 100644 --- a/src/LiquidCrystal.cpp +++ b/src/LiquidCrystal.cpp @@ -182,6 +182,10 @@ void LiquidCrystal::home() void LiquidCrystal::setCursor(uint8_t col, uint8_t row) { + const size_t max_lines = sizeof(_row_offsets) / sizeof(*_row_offsets); + if ( row >= max_lines ) { + row = max_lines - 1; // we count rows starting w/0 + } if ( row >= _numlines ) { row = _numlines - 1; // we count rows starting w/0 } From 596e305a4d115ee53132e99ac3d9a07ab752f837 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 18 Dec 2013 12:54:53 +0100 Subject: [PATCH 11/19] Support more LiquidCrystal displays out of the box Previously, the row offsets were hardcoded to the ones used for 20x4 displays (which woudl also work for all 2-line displays). Now, the number of columns given is used to calculate the offsets most likely to apply. For 2-line displays and 20x4 displays, the (used) offsets are completel unchanged. With this change, common 16x4 displays and (if they even exist) other 4-line and 3-line displays might also work (depending on the hardware configuration used, of course). See this page for some info on common LCD sizes and configurations encountered in practice: http://web.alfredstate.edu/weimandn/lcd/lcd_addressing/lcd_addressing_index.html --- src/LiquidCrystal.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LiquidCrystal.cpp b/src/LiquidCrystal.cpp index 27b5377..5825945 100644 --- a/src/LiquidCrystal.cpp +++ b/src/LiquidCrystal.cpp @@ -79,8 +79,6 @@ void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t en else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; - setRowOffsets(0x00, 0x40, 0x14, 0x54); - begin(16, 1); } @@ -91,6 +89,8 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { _numlines = lines; _currline = 0; + setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols); + // for some 1 line displays you can select a 10 pixel high font if ((dotsize != 0) && (lines == 1)) { _displayfunction |= LCD_5x10DOTS; From c2a0d844b605bad78fa032aa1bd2f3c635ed232a Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 18 Dec 2013 13:01:11 +0100 Subject: [PATCH 12/19] In LiquidCrystal::begin(), use a define instead of a hardcoded 0 --- src/LiquidCrystal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LiquidCrystal.cpp b/src/LiquidCrystal.cpp index 5825945..9579c01 100644 --- a/src/LiquidCrystal.cpp +++ b/src/LiquidCrystal.cpp @@ -92,7 +92,7 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols); // for some 1 line displays you can select a 10 pixel high font - if ((dotsize != 0) && (lines == 1)) { + if ((dotsize != LCD_5x8DOTS) && (lines == 1)) { _displayfunction |= LCD_5x10DOTS; } From dbb718a53e767737815616ab682b62794b40febb Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Wed, 18 Dec 2013 13:02:05 +0100 Subject: [PATCH 13/19] In LiquidCrystal, remove an unused variable --- src/LiquidCrystal.cpp | 1 - src/LiquidCrystal.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/LiquidCrystal.cpp b/src/LiquidCrystal.cpp index 9579c01..58120e8 100644 --- a/src/LiquidCrystal.cpp +++ b/src/LiquidCrystal.cpp @@ -87,7 +87,6 @@ void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { _displayfunction |= LCD_2LINE; } _numlines = lines; - _currline = 0; setRowOffsets(0x00, 0x40, 0x00 + cols, 0x40 + cols); diff --git a/src/LiquidCrystal.h b/src/LiquidCrystal.h index 684a65f..da950ce 100644 --- a/src/LiquidCrystal.h +++ b/src/LiquidCrystal.h @@ -101,7 +101,7 @@ private: uint8_t _initialized; - uint8_t _numlines,_currline; + uint8_t _numlines; uint8_t _row_offsets[4]; }; From e71db845e78fc41fc243dc5aaf3abe4ce13bbab4 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 18 Feb 2014 17:22:40 +0100 Subject: [PATCH 14/19] Updated all library.properties to 1.5 rev2 lib format --- library.properties | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library.properties b/library.properties index d67278b..039677d 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,8 @@ name=LiquidCrystal +version=1.0 author= -email= +maintainer=Arduino sentence=Write to an alphanumeric LCD display. paragraph=This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4 or 8 bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines). url=http://arduino.cc/en/Reference/LiquidCrystal architectures=* -version=1.0 -dependencies= -core-dependencies=arduino (>=1.5.0) From 32c6f8c74613569f2440b077638a9428bce5c493 Mon Sep 17 00:00:00 2001 From: Fede85 Date: Fri, 18 Jul 2014 19:11:54 +0200 Subject: [PATCH 15/19] modified sentences in library.properties files --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 039677d..514b293 100644 --- a/library.properties +++ b/library.properties @@ -2,7 +2,7 @@ name=LiquidCrystal version=1.0 author= maintainer=Arduino -sentence=Write to an alphanumeric LCD display. +sentence=Allows communication with alphanumerical liquid crystal displays (LCDs). For all Arduino boards. paragraph=This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4 or 8 bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines). url=http://arduino.cc/en/Reference/LiquidCrystal architectures=* From 71761686591ef06e0e076c129181e00e6b05cfdf Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 7 Nov 2014 19:24:12 +0100 Subject: [PATCH 16/19] Added missing keyword in LiquidCrystal library --- keywords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/keywords.txt b/keywords.txt index 132845c..4ee24d9 100644 --- a/keywords.txt +++ b/keywords.txt @@ -30,6 +30,7 @@ rightToLeft KEYWORD2 scrollDisplayLeft KEYWORD2 scrollDisplayRight KEYWORD2 createChar KEYWORD2 +setRowOffsets KEYWORD2 ####################################### # Constants (LITERAL1) From 6d32f53cda15d3e9a76cf515a1ae6a3b5eb855fb Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 29 Aug 2014 15:16:19 +0200 Subject: [PATCH 17/19] Fixed some libraries metadata. --- library.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/library.properties b/library.properties index 514b293..05d2c9f 100644 --- a/library.properties +++ b/library.properties @@ -4,5 +4,6 @@ author= maintainer=Arduino sentence=Allows communication with alphanumerical liquid crystal displays (LCDs). For all Arduino boards. paragraph=This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. The library works with in either 4 or 8 bit mode (i.e. using 4 or 8 data lines in addition to the rs, enable, and, optionally, the rw control lines). +category=Display url=http://arduino.cc/en/Reference/LiquidCrystal architectures=* From c9c5d64a4523b24a9085921465f747ac4c7b93da Mon Sep 17 00:00:00 2001 From: Arturo Guadalupi Date: Fri, 16 Jan 2015 15:35:22 +0100 Subject: [PATCH 18/19] Added README.adoc for the library manager project --- README.adoc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 README.adoc diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..6f57eb1 --- /dev/null +++ b/README.adoc @@ -0,0 +1,24 @@ += Liquid Crystal Library for Arduino = + +This library allows an Arduino board to control LiquidCrystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. + +For more information about this library please visit us at +http://arduino.cc/en/Reference/LiquidCrystal + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA From ea5de4455a8f3f8b4c022bca15d6cd424aef2159 Mon Sep 17 00:00:00 2001 From: Arturo Guadalupi Date: Mon, 12 Jan 2015 14:37:50 +0100 Subject: [PATCH 19/19] Cherry picked fix from 87865ac19df2f55e3d073cf5dc7ba08c0de4c584 --- examples/setCursor/setCursor.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/setCursor/setCursor.ino b/examples/setCursor/setCursor.ino index 689f329..4790b68 100644 --- a/examples/setCursor/setCursor.ino +++ b/examples/setCursor/setCursor.ino @@ -60,7 +60,7 @@ void loop() { // loop over the rows: for (int thisRow = 0; thisRow < numCols; thisRow++) { // set the cursor position: - lcd.setCursor(thisRow, thisCol); + lcd.setCursor(thisCol, thisRow); // print the letter: lcd.write(thisLetter); delay(200);