mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Adding Tom's examples for the new LiquidCrystal library.
This commit is contained in:
parent
5b5e739645
commit
abbf61fa2b
56
hardware/libraries/LiquidCrystal/examples/Blink/Blink.pde
Normal file
56
hardware/libraries/LiquidCrystal/examples/Blink/Blink.pde
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Turn off the display:
|
||||
lcd.noBlink();
|
||||
delay(500);
|
||||
// Turn on the display:
|
||||
lcd.blink();
|
||||
delay(500);
|
||||
}
|
||||
|
||||
|
55
hardware/libraries/LiquidCrystal/examples/Cursor/Cursor.pde
Normal file
55
hardware/libraries/LiquidCrystal/examples/Cursor/Cursor.pde
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Turn off the display:
|
||||
lcd.noCursor();
|
||||
delay(500);
|
||||
// Turn on the display:
|
||||
lcd.cursor();
|
||||
delay(500);
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
// 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);
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
// 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);
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
LiquidCrystal Library - Increment/Decrement
|
||||
|
||||
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 shiftIncrement()
|
||||
and shifDecrement() functions.
|
||||
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// set the cursor to (0,0):
|
||||
lcd.setCursor(0, 0);
|
||||
// set the display to left justify:
|
||||
lcd.shiftDecrement();
|
||||
// print from 0 to 9:
|
||||
for (int thisChar = 0; thisChar < 10; thisChar++) {
|
||||
lcd.print(thisChar);
|
||||
delay(500);
|
||||
}
|
||||
// set the cursor to (16,0):
|
||||
lcd.setCursor(16,1);
|
||||
// set the display to left justify:
|
||||
lcd.shiftIncrement();
|
||||
// print from 0 to 9:
|
||||
for (int thisChar = 0; thisChar < 10; thisChar++) {
|
||||
lcd.print(thisChar);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// clear screen for the next loop:
|
||||
lcd.clear();
|
||||
}
|
||||
|
65
hardware/libraries/LiquidCrystal/examples/Scroll/Scroll.pde
Normal file
65
hardware/libraries/LiquidCrystal/examples/Scroll/Scroll.pde
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
lcd.setCursor(0,7);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("hello, world!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// scroll 27 positions (display length + string length) to the left:
|
||||
for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
|
||||
// scroll one position left:
|
||||
lcd.scrollDisplayLeft();
|
||||
// wait a bit:
|
||||
delay(200);
|
||||
}
|
||||
|
||||
// scroll 27 positions (display length + string length) to the right:
|
||||
for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
|
||||
// scroll one position right:
|
||||
lcd.scrollDisplayRight();
|
||||
// wait a bit:
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
82
hardware/libraries/LiquidCrystal/examples/Shift/Shift.pde
Normal file
82
hardware/libraries/LiquidCrystal/examples/Shift/Shift.pde
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
LiquidCrystal Library - Shift
|
||||
|
||||
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 shiftLeft() and shiftRight()
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(2, 16);
|
||||
// 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.shiftRight();
|
||||
}
|
||||
// reverse again at 's':
|
||||
if (thisChar == 's') {
|
||||
// go left for the next letter
|
||||
lcd.shiftLeft();
|
||||
}
|
||||
// reset at 'z':
|
||||
if (thisChar > 'z') {
|
||||
// go to (0,0):
|
||||
lcd.home();
|
||||
// start again at 0
|
||||
thisChar = 'a';
|
||||
}
|
||||
// print the character
|
||||
lcd.print(thisChar, BYTE);
|
||||
// wait a second:
|
||||
delay(1000);
|
||||
// increment the letter:
|
||||
thisChar++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
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
|
||||
* 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
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/LiquidCrystal
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// 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 rows and columns:
|
||||
lcd.begin(numRows, numCols);
|
||||
}
|
||||
|
||||
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.print(thisLetter, BYTE);
|
||||
delay(200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user