16x2 individual scroll

this code allows you to scroll on two separate lines of
a 16 x 2 LCD without scrolling both at once. I understand
scroll from right. but the scroll from left has gone over my
head.

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// Declare lcd as a LiquidCrystal Object

int i = 0;

int j = 0;

int k = 0;

int delayTime2 = 350; // Delay between shifts

void scrollInFromRight (int line, char str1) {

// Written by R. Jordan Kreindler June 2016

i = strlen(str1);

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

lcd.setCursor(0, line);

for (k = 0; k <= 15; k++) {

lcd.print(" "); // Clear line

}

lcd.setCursor(j, line);

lcd.print(str1);

delay(delayTime2);

}

}

void scrollInFromLeft (int line, char str1) {

// Written by R. Jordan Kreindler June 2016

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 setup() {

Serial.begin(9600);

Serial.println(“Starting test …”);

lcd.begin(16, 2);

lcd.clear();

lcd.print(“Test Only”);

}

void loop() {

lcd.clear();

scrollInFromRight(0, “Line1 From Right”);

scrollInFromRight(1, “Line2 From Right”);

lcd.clear();

scrollInFromLeft(0, “Line1 From Left.”);

scrollInFromLeft(1, “Line2 From Left.”);

lcd.clear();

scrollInFromRight(0, “Line1 From Right”);

scrollInFromLeft(1, “Line2 From Left.”);

lcd.clear();

}

can someone please describe to me the fade from left portion of this code?

Please edit your post to add code tags, as described in "How to use this forum".

First, you need to heed jremington’s advice and use code tags (the </> icon on the tool bar) to post your code.

Second, use Ctrl-T in the IDE source code window to reformat your code into a common C style.

Third, what do you suppose this statement does:

i = 40 - strlen(str1);
in light of what’s in the loops?

Fourth, most C programmers would write this line:

line = line - 1;

as

line–;

It probably won’t have any impact on your code because the compiler probably makes the change anyway.

Fifth, instead of this:

  • for (k = 0; k <= 15; k++) {*
  • lcd.print(" "); // Clear line*
  • }*

why not use this:

// Do at top of loop…
char spaces[17]; // Need one for the NULL
memset(spaces, ’ ', sizeof(spaces));

lcd.print(spaces); // Use this instead of the k loop