// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
String
storedMsgTop = "THIS IS TOP MESSAGE!",
storedMsgBtm = "THIS IS BOTTOM MESSAGE!";
String*
rows[2] = { &storedMsgTop, &storedMsgBtm };
void printMsg() {
byte
l,
r_len[2] = { rows[0]->length(), rows[1]->length() },
maxP = ((r_len[0] >= r_len[1] ) ? r_len[0] : r_len[1]) ;
Serial.print("topMsg Len: ");Serial.println(r_len[0]);
Serial.print("btmMsg Len: ");Serial.println(r_len[1]);
Serial.print("max scrollLen: ");Serial.println(maxP);
lcd.clear();
for (l = 0; l < 2; l++)
lcd.setCursor(0,l), lcd.print( rows[l]->substring(0,16));
delay(1000);
if (maxP > 16) {
for (byte p = 0; p <= (maxP-16); p++) {
for (l = 0; l < 2; l++) {
if ((p + 16) <= r_len[l]) {
lcd.setCursor(0, l);
lcd.print(rows[l]->substring(p, r_len[l]));
}
}
delay(100);
}
}
delay(1000);
/*
// BOTH LINES (SUBSTRINGS):
if (maxP > 16) {
for (byte p = 0; p <= (maxP-16); p++) {
Serial.println(p); //Serial.print(" ");
for (l = 0; l < 2; l++) {
Serial.print(" ");Serial.println(l); Serial.print(" ");
Serial.print("pos: "),Serial.print((p + 16)), Serial.print("/"),Serial.println(r_len[l]);Serial.print(" ");
if ((p + 16) <= r_len[l]) {
//Serial.print(" LINE "), Serial.print(l),
Serial.println(rows[l]->substring(p, r_len[l]));
}
}
delay(1000);
}
}
*/
/*
// SINGLE LINE:
if (maxP > 16) {
for (byte p = 0; p <= (maxP-16); p++) {
lcd.setCursor(0, 0);
// Print substring:
//lcd.print(rows[0]->substring(p, r_len[0]));
// print each char:
for (int i = p; i < r_len[0]; i++) {
char c = (*rows[0])[i];
//lcd.setCursor(0, 0);
lcd.print((*rows[0])[i]);
Serial.print(c);
}
delay(1000);
}
}
*/
/*
// BOTH LINES
if (maxP > 16) {
for (byte p = 0; p < (maxP-16); p++) {
Serial.print("p:"),Serial.println(p);
for (l = 0; l < 2; l++) {
if (r_len[l] > 16) {
lcd.setCursor(0, l);
char Char = ((p < r_len[0]) ? (*rows[0])[p] : char(" "));
//Serial.print("c:"), Serial.println(c);
lcd.print(Char);
delay(1000);
}
}
}
}
*/
/*
if (maxP > 16) {
for (byte p = 0; p < maxP; p++) {
lcd.setCursor(0,0), lcd.print((p < r_len[0]) ? (*rows[0])[p] : " ");
lcd.setCursor(0,1), lcd.print((p < r_len[1]) ? (*rows[1])[p] : " ");
}
}
*/
}
/*
void scrollMsg(byte row, byte start, byte startChar) {
lcd.setCursor(start, 0);
for (byte c = startChar; c <= startChar + 15; c++)
lcd.print((c < topMsgLength) ? topMsg[c] : char(" "));
delay_func(scrollDelay);
}
*/
void setup() {
Serial.begin(9600);
Serial.println("READY!");
lcd.begin(16, 2);
lcd.print("Hello World!");
delay(1000);
}
void loop() {
printMsg();
}