Created
July 11, 2015 02:56
-
-
Save nyitgroup/7d90ed973b84d0cadd97 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
#include <LiquidCrystal.h> | |
#include <string.h> | |
// initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
int stringNum = 1; | |
int previous = 0; | |
int pos = 0; | |
void setup() { | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// Print a message to the LCD. | |
//lcd.print(message); | |
} | |
void printLine(int refreshSeconds,char message[] ){ | |
//Check if the current second since restart is a mod of refresh seconds , | |
//if it is then update the display , it must also not equal the previously | |
//stored value to prevent duplicate refreshes | |
if((millis()) % refreshSeconds == 0 && previous != (millis())){ | |
previous = (millis());//Store the current time we entered for comparison on the next cycle | |
lcd.setCursor(0, 1);//Set our draw position , set second param to 0 to use the top line | |
char lcdTop[16];//Create a char array to store the text for the line | |
int copySize = 16; // What is the size of our screen , this could probably be moved outside the loop but its more dynamic like this | |
if(strlen(message) < 16) | |
{ | |
//if the message is bigger than the current buffer use its length instead; | |
copySize = strlen(message); | |
} | |
//Store the current position temporarily and invert its sign if its negative since we are going in reverse | |
int tempPos = pos; | |
if(tempPos < 0) | |
{ | |
tempPos = -(tempPos); | |
} | |
//Build the lcd text by copying the required text out of our template message variable | |
memcpy(&lcdTop[0],&message[tempPos],copySize); | |
lcd.print(lcdTop);//Print it from position 0 | |
//Increase the current position and check if the position + 16 (screen size) would be larger than the message length , if it is go in reverse by inverting the sign. | |
pos += 1; | |
if(pos +16 == strlen(message)) | |
{ | |
// pos = -(pos); | |
previous = 0; | |
pos = 0; | |
stringNum++; | |
} | |
} | |
} | |
void loop() { | |
switch(stringNum) | |
{ | |
case 1: | |
{ | |
char message1[] = " This is some long message that will end up scrolling"; | |
printLine(500,message1); | |
} | |
break; | |
case 2: | |
{ char message2[] = " second message 1 2 3 4 5 6 7 8 9 0 long message "; | |
printLine(500,message2); | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment