Convert library examples

This commit is contained in:
2016-08-28 21:30:18 +01:00
parent 768ab1254d
commit 8c441b7ccd
11 changed files with 177 additions and 176 deletions

View File

@@ -1,74 +1,74 @@
/* /*
LiquidCrystal Library - Autoscroll LiquidCrystal Library - Autoscroll
Demonstrates the use a 16x2 LCD display. The LiquidCrystal 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 Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface. can usually tell them by the 16-pin interface.
This sketch demonstrates the use of the autoscroll() This sketch demonstrates the use of the autoscroll()
and noAutoscroll() functions to make new text scroll or not. and noAutoscroll() functions to make new text scroll or not.
The circuit: The circuit:
* LCD RS pin to digital pin 12 * LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11 * LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5 * LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4 * LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3 * LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2 * LCD D7 pin to digital pin 2
* LCD R/W pin to ground * LCD R/W pin to ground
* 10K resistor: * 10K resistor:
* ends to +5V and ground * ends to +5V and ground
* wiper to LCD VO pin (pin 3) * wiper to LCD VO pin (pin 3)
Library originally added 18 Apr 2008 Library originally added 18 Apr 2008
by David A. Mellis by David A. Mellis
library modified 5 Jul 2009 library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net) by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009 example added 9 Jul 2009
by Tom Igoe by Tom Igoe
modified 22 Nov 2010 modified 22 Nov 2010
by Tom Igoe by Tom Igoe
This example code is in the public domain. This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll http://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll
*/ */
// include the library code: // include the library code:
#include <LiquidCrystal.h> #include <Arduino.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() {
// set up the LCD's number of columns and rows: void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
} lcd.begin(16, 2);
}
void loop() {
// set the cursor to (0,0): void loop() {
lcd.setCursor(0, 0); // set the cursor to (0,0):
// print from 0 to 9: lcd.setCursor(0, 0);
for (int thisChar = 0; thisChar < 10; thisChar++) { // print from 0 to 9:
lcd.print(thisChar); for (int thisChar = 0; thisChar < 10; thisChar++) {
delay(500); lcd.print(thisChar);
} delay(500);
}
// set the cursor to (16,1):
lcd.setCursor(16, 1); // set the cursor to (16,1):
// set the display to automatically scroll: lcd.setCursor(16, 1);
lcd.autoscroll(); // set the display to automatically scroll:
// print from 0 to 9: lcd.autoscroll();
for (int thisChar = 0; thisChar < 10; thisChar++) { // print from 0 to 9:
lcd.print(thisChar); for (int thisChar = 0; thisChar < 10; thisChar++) {
delay(500); lcd.print(thisChar);
} delay(500);
// turn off automatic scrolling }
lcd.noAutoscroll(); // turn off automatic scrolling
lcd.noAutoscroll();
// clear screen for the next loop:
lcd.clear(); // clear screen for the next loop:
} lcd.clear();
}

View File

@@ -37,10 +37,11 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:

View File

@@ -38,10 +38,11 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:
@@ -57,5 +58,4 @@ void loop() {
// Turn on the cursor: // Turn on the cursor:
lcd.cursor(); lcd.cursor();
delay(500); delay(500);
} }

View File

@@ -39,10 +39,11 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// make some custom characters: // make some custom characters:
byte heart[8] = { byte heart[8] = {
@@ -137,4 +138,4 @@ void loop() {
// draw him arms up: // draw him arms up:
lcd.write(4); lcd.write(4);
delay(delayTime); delay(delayTime);
} }

View File

@@ -38,10 +38,11 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:
@@ -57,5 +58,4 @@ void loop() {
// Turn on the display: // Turn on the display:
lcd.display(); lcd.display();
delay(500); delay(500);
} }

View File

@@ -38,10 +38,11 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:
@@ -56,5 +57,4 @@ void loop() {
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
// print the number of seconds since reset: // print the number of seconds since reset:
lcd.print(millis() / 1000); lcd.print(millis() / 1000);
} }

View File

@@ -38,10 +38,11 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:
@@ -81,6 +82,4 @@ void loop() {
// delay at the end of the full loop: // delay at the end of the full loop:
delay(1000); delay(1000);
}
}

View File

@@ -36,10 +36,11 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:
@@ -61,4 +62,4 @@ void loop() {
lcd.write(Serial.read()); lcd.write(Serial.read());
} }
} }
} }

View File

@@ -37,6 +37,7 @@
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// these constants won't change. But you can change the size of // these constants won't change. But you can change the size of
@@ -45,7 +46,7 @@ const int numRows = 2;
const int numCols = 16; const int numCols = 16;
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup() { void setup() {
// set up the LCD's number of columns and rows: // set up the LCD's number of columns and rows:
@@ -67,6 +68,4 @@ void loop() {
} }
} }
} }
} }

View File

@@ -37,10 +37,11 @@ http://www.arduino.cc/en/Tutorial/LiquidCrystalTextDirection
*/ */
// include the library code: // include the library code:
#include <Arduino.h>
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int thisChar = 'a'; int thisChar = 'a';

View File

@@ -1,80 +1,79 @@
#include "Arduino.h" #include <Arduino.h>
#include <LiquidCrystal.h>
extern "C" {
#include "pb_decode.h" extern "C" {
#include "pb_encode.h" #include "pb_decode.h"
#include "lcdkeypad.pb.h" #include "pb_encode.h"
} #include "lcdkeypad.pb.h"
}
#include <LiquidCrystal.h>
// Select the pins used on the LCD panel
// Select the pins used on the LCD panel LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Define some values used by the panel and buttons
// Define some values used by the panel and buttons int lcd_key = 0;
int lcd_key = 0; int adc_key_in = 0;
int adc_key_in = 0; #define btnRIGHT 0
#define btnRIGHT 0 #define btnUP 1
#define btnUP 1 #define btnDOWN 2
#define btnDOWN 2 #define btnLEFT 3
#define btnLEFT 3 #define btnSELECT 4
#define btnSELECT 4 #define btnNONE 5
#define btnNONE 5
// Read the buttons
// Read the buttons int read_LCD_buttons() {
int read_LCD_buttons() { // Read the value from the sensor
// Read the value from the sensor adc_key_in = analogRead(0);
adc_key_in = analogRead(0);
// Map buttons (v1.0 hardware)
// Map buttons (v1.0 hardware) if (adc_key_in > 1000) return btnNONE;
if (adc_key_in > 1000) return btnNONE; if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 195) return btnUP;
if (adc_key_in < 195) return btnUP; if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 380) return btnDOWN; if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 555) return btnLEFT; if (adc_key_in < 790) return btnSELECT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
return btnNONE; // when all others fail, return this... }
}
void setup() {
void setup() { lcd.begin(16, 2);
lcd.begin(16, 2); lcd.setCursor(0, 0);
lcd.setCursor(0, 0); lcd.print("Push the buttons");
lcd.print("Push the buttons"); }
}
void loop() {
void loop() { // Move cursor to second line "1" and 9 spaces over
// Move cursor to second line "1" and 9 spaces over lcd.setCursor(9, 1);
lcd.setCursor(9, 1);
// Display seconds elapsed since power-up
// Display seconds elapsed since power-up lcd.print(millis()/1000);
lcd.print(millis()/1000);
// Move to the start of the second line
// Move to the start of the second line lcd.setCursor(0, 1);
lcd.setCursor(0, 1);
// Read the buttons
// Read the buttons lcd_key = read_LCD_buttons();
lcd_key = read_LCD_buttons();
// Print button status
// Print button status switch (lcd_key) {
switch (lcd_key) { case btnRIGHT:
case btnRIGHT: lcd.print("RIGHT ");
lcd.print("RIGHT "); break;
break; case btnLEFT:
case btnLEFT: lcd.print("LEFT ");
lcd.print("LEFT "); break;
break; case btnUP:
case btnUP: lcd.print("UP ");
lcd.print("UP "); break;
break; case btnDOWN:
case btnDOWN: lcd.print("DOWN ");
lcd.print("DOWN "); break;
break; case btnSELECT:
case btnSELECT: lcd.print("SELECT");
lcd.print("SELECT"); break;
break; case btnNONE:
case btnNONE: lcd.print("NONE ");
lcd.print("NONE "); break;
break; }
}
} }