This is the sketch we use to test our LCDs. You can use it to give you an idea how to work with it and modify to fit your needds
This sketch will display a series of numbers 0-44 on a LCD screen 20x4 filling each line with consecutive numbers until it reaches the end and then it starts again.
/*
This sketch will display a series of numbers 0-44 on a LCD screen 20x4 filling each line with consecutive numbers until it reaches
the end and then it starts again.
Code used for learning purposes developed by: www.HackerspaceLA.org | @hackerspacela
Code modified from Adafruit at: https://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll
This example code is in the public domain: http://www.arduino.cc/en/Tutorial/LiquidCrystalAutoscroll
*/
// include the library code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//#define pins:
#define I2C_ADDR 0x27 // LCD address (make sure you run the I2C scanner to verify our LCD address)
#define Rs_pin 0 // Assign pins between I2C and LCD
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// initialize the library with the numbers of the interface pins
void setup() {
// set up backlight and turn on module:
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
// set up the LCD's number of columns and rows:
lcd.begin(20, 4); //My LCD is 20x4
}
void loop() {
// set the cursor to (0, 0) on line #1
lcd.setCursor (0, 0);
//lcd.autoscroll();
// print from 0 to 14:
for (int thisChar = 0; thisChar < 15; thisChar++) {
lcd.print(thisChar);
lcd.leftToRight();
delay(500);
}
// set the cursor to (0, 1) on line #2
lcd.setCursor (0, 1);
// set the display to automatically scroll:
//lcd.autoscroll();
// print from 0 to 14:
for (int thisChar = 15; thisChar < 25; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// set the cursor to (0, 1) on line #3
lcd.setCursor (0, 2);
// set the display to automatically scroll:
//lcd.autoscroll();
// print from 0 to 14:
for (int thisChar = 25; thisChar < 35; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// set the cursor to (0, 1) on line #4
lcd.setCursor (0, 3);
// set the display to automatically scroll:
//lcd.autoscroll();
// print from 0 to 14:
for (int thisChar = 35; thisChar < 45; thisChar++) {
lcd.print(thisChar);
delay(500);
}
// turn off automatic scrolling
lcd.noAutoscroll();
// clear screen for the next loop:
lcd.clear();
}