You are on page 1of 2

#include <LiquidCrystal.

h> // include the library code


LiquidCrystal lcd(5, 6, 7, 8, 9, 10); // initialize the library with the interface
pins
int i = 0;
int j = 0;
int k = 0;
int delayTime2 = 150; // delay between shifts

void scrollInFromRight (int line, char str1[]) {


i = strlen(str1); // strlen() function is used to get the length of the string

for (j = 16; j >= 0; j--) {


lcd.setCursor(0, line);
for (k = 0; k <= 15; k++) {
lcd.print(" "); // clear line
}
lcd.setCursor(j, line); //set cursor to column, line
lcd.print(str1); //display first string of chars
delay(delayTime2); //wait a bit
}
}
void scrollInFromLeft (int line, char str1[]) {
i = 40 - strlen(str1);
line = line - 1;
for (j = i; j <= i + 16; j++) {
for (k = 0; k <= 15; k++) {
lcd.print(" "); // clear line
}
lcd.setCursor(j, line);
lcd.print(str1);
delay(delayTime2);
}

}
void scrollInFromLeft1 (int line, char str1[]) {
i = strlen(str1);

for (j = 0; j <=i; j++) {


lcd.setCursor(0, line);
for (k = 0; k <= 15; k++) {
lcd.print(" "); // clear line
}
lcd.setCursor(j, line); //set cursor to column, line
lcd.print(str1); //display first string of chars
delay(delayTime2); //wait a bit
}
}

void setup() {
Serial.begin (115200); // initialize serial comms at 115200 baud
Serial.println("Starting test ...");
lcd.begin(16, 2); //16 character by two line display
lcd.clear();
lcd.setCursor(1,0); //set cursor to column 2 row 1
lcd.print("Press a button!");
pinMode(11, INPUT); //clearly defines the input pin at 5 volts
pinMode(12, INPUT); //clearly defines the input pin at 5 volts
}

void loop() {
if (digitalRead(11) == HIGH) {
lcd.clear();
scrollInFromRight(0, "Right to left!!!"); //scrollInFromRight (line to display text
on, string to be scrolled)
lcd.clear();
scrollInFromRight(1, "Right to left!!!");
lcd.clear(); //scroll text one line at a time
}else if (digitalRead(12) == HIGH) {
lcd.clear();
scrollInFromLeft(1, "Left to right!!!");
lcd.clear();
scrollInFromLeft1(0, "Left to right!!!");
lcd.clear();
}
}

You might also like