-
-
Save phloreenm/4984c5936e41056bc84cc4d33973a4ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Scrolling display for 1602 LCD by Arduino | |
// by Varad Kulkarni <http://www.microcontrollershub.com> | |
// Created on 20 May 2018 | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
// Change following variables as per your need | |
char * LargeText = " Understanding code for scrolling text on 16*2 LCD Display. "; | |
int iLineNumber = 1; // Line number to show your string (Either 0 or 1) | |
int iCursor = 0; | |
void setup() | |
{ | |
lcd.begin(16, 2); | |
} | |
void loop() | |
{ | |
UpdateLCDDisplay(); // Scoll text by 1 character | |
delay(150); // Change delay to change speed for scrollig text. | |
} | |
void UpdateLCDDisplay() | |
{ | |
int iLenOfLargeText = strlen(LargeText); // Calculate lenght of string. | |
if (iCursor == (iLenOfLargeText - 1) ) // Reset variable for rollover effect. | |
{ | |
iCursor = 0; | |
} | |
//lcd.clear(); | |
lcd.setCursor(0,iLineNumber); | |
if(iCursor < iLenOfLargeText - 16) // This loop exicuted for normal 16 characters. | |
{ | |
for (int iChar = iCursor; iChar < iCursor + 16 ; iChar++) | |
{ | |
lcd.print(LargeText[iChar]); | |
} | |
} | |
else | |
{ | |
for (int iChar = iCursor; iChar < (iLenOfLargeText - 1) ; iChar++) // This code takes care of printing charecters of current string. | |
{ | |
lcd.print(LargeText[iChar]); | |
} | |
for (int iChar = 0; iChar <= 16 - (iLenOfLargeText - iCursor); iChar++) // Reamining charecter will be printed by this loop. | |
{ | |
lcd.print(LargeText[iChar]); | |
} | |
} | |
iCursor++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment