Pages: [1]   Go Down
Author Topic: How to move text over to flash/how to scroll it on my LCD  (Read 664 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My serial LCD display, automatically writes to the next line, when the end of the first line is reached, and it also automatically scrolls the lines up 1, once the end of the 2nd line is reached. (MatrixOrbital LK162), so it's very easy to send a sentence to the display with a time based function like this code below.
Code:
sendMessage("This sentence is an example of one of a several text strings I have in my program that I want to scroll on my LCD display");


void sendMessage(char myMessage[]) {
    i = 0;  //reset display character counter
    LCDclear();
    while(1) {  //loop
        if(millis() - prevLCDtime > 100 ) {  //continue every 10 ms
            prevLCDtime = millis();        //update the time counter
            Serial.print(myMessage[i]);    //print the next letter to the display
            i = i + 1; //increase counter
            if (i == strlen(myMessage)) break;  //when the counter i gets to the end of the message, break
        }
    }
    delay(1000);  //time to read the last line
}
  But I'm wanting to move a lot of these sentences to flash memory, via:
http://arduiniana.org/libraries/flash/
I understand what they're saying there pretty well, but not sure how to use it in conjuntion with my code, as I need to print the characters of my message one by one on a time based interval, to give the user time to read the display.
Any ideas?  My concept of printing to the display works well like it is, but maybe there's a better way to do it??
Logged

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...how to use it...to print the characters of my message one by one on a time based interval,...


One way, using the Flash library (I'll just use plain old Serial.print without any LCD stuff):

Code:
#include <Flash.h>

FLASH_STRING(universe,
   "There is a theory which states that if ever for any reason "
   "anyone discovers what exactly the Universe is for and why "
   "it is here it will instantly disappear and be replaced by "
   "something even more bizarre and inexplicable. There is "
   "another that states that this has already happened.  "
   "---Douglas Adams "
   "\"The Restaurant at the End of the Universe\"");


void setup()
{
    Serial.begin(9600);
}

void loop()
{
    printFlashString(universe, 100); // 100 ms between characters
    delay(1000);
    Serial.println();Serial.println();
}
//
// Print the FLASH_STRING a character at a time with a given delay
//
void printFlashString(const _FLASH_STRING & flashStr, const unsigned long & msDelay)
{
    for (int i = 0; flashStr[i] != '\0'; i++) {
        Serial.print(flashStr[i]);
        delay(msDelay);
    }
}


Regards,

Dave
« Last Edit: May 01, 2011, 12:51:53 am by davekw7x » Logged

South East USA
Offline Offline
God Member
*****
Karma: 5
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks, that's not so hard!
Logged

Pages: [1]   Go Up
Jump to: