Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save microcontrollershub/41f5451073aaebcb82c586e647fe5adb to your computer and use it in GitHub Desktop.
Save microcontrollershub/41f5451073aaebcb82c586e647fe5adb to your computer and use it in GitHub Desktop.
Code for connecting 2 LCD display to Arduino board with just 7 digital I/O pins. Project explanation - https://youtu.be/DFX627wrCvE
// Connecting multiple 16*2 LCD Display to Arduino
// by Varad Kulkarni <http://www.microcontrollershub.com>
// Created on 18 June 2018
#include <LiquidCrystal.h>
LiquidCrystal lcd1(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd2(12, 10, 5, 4, 3, 2);
// Change following variables as per your need
char * LargeText = " Connecting 2 - 16*2 LCD with Arduino by microcontrollershub. ";
int iLineNumber = 1; // Line number to show your string (Either 0 or 1)
int iCursor = 0;
void setup()
{
lcd1.begin(16, 2); // Initialise both LCD.
lcd2.begin(16, 2);
lcd1.clear();
lcd2.clear();
}
void loop()
{
UpdateLCDDisplay(); // Update text on LCD Display.
delay(160); // Change this value to change speed of scrolling text.
lcd1.clear();
lcd2.clear();
delay(60);
}
void UpdateLCDDisplay()
{
int iLenOfLargeText = strlen(LargeText); // Calculate length of string.
if (iCursor == (iLenOfLargeText - 1) ) // Reset variable for rollover effect.
{
iCursor = 0;
}
lcd1.setCursor(0,iLineNumber);
lcd2.setCursor(0,iLineNumber);
if(iCursor < iLenOfLargeText - 32) // This loop executed for normal 16 characters.
{
for (int iChar = iCursor; iChar < iCursor + 16 ; iChar++)
{
lcd1.print(LargeText[iChar]);
}
for (int iChar = iCursor + 16 ; iChar < iCursor + 32 ; iChar++)
{
lcd2.print(LargeText[iChar]);
}
}
else
{
for (int iChar = iCursor; iChar < (iLenOfLargeText - 1) ; iChar++) // This code takes care of printing characters of current string.
{
if(16 > (iChar - iCursor))
{
lcd1.print(LargeText[iChar]);
}
else
{
lcd2.print(LargeText[iChar]);
}
}
for (int iChar = 0; iChar <= 32 - (iLenOfLargeText - iCursor); iChar++) // Remaining characters will be printed by this loop.
{
if(16 > (32 - (iLenOfLargeText - iCursor)))
{
lcd2.print(LargeText[iChar]);
}
else
{
if( ((32 - (iLenOfLargeText - iCursor)) - 16) >= iChar)
{
lcd1.print(LargeText[iChar]);
}
else
{
lcd2.print(LargeText[iChar]);
}
}
}
}
iCursor++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment