Go Down

Topic: Nokia LCD display shield question (Read 5 times) previous topic - next topic


Hey Guys...

With this tutorial (Link) i put the LCD to work, however everything appears in mirror and upside down. How can I solve this problem?


Tom Carpenter

Oct 12, 2012, 01:40 am Last Edit: Oct 12, 2012, 01:46 am by Tom Carpenter Reason: 1
I have simplified one of the functions from my my MP3 Player. This basically displays data from a string which you supply, scrolling it around by 1 character each time the function is called.
Code: [Select]
//Scroll through songInfo, shifting 1 characters each time
void printScroll(char* songInfo, byte infoLength, boolean start = false);
void printScroll(char* songInfo, byte infoLength, boolean start){
 static unsigned int tagPosition = 0;
   tagPosition = 0;
 char stringRecover[23] = {0};
 strncpy(stringRecover,&songInfo[tagPosition], 22); //22 character substring starting at [tagPosition]
 tagPosition += 1;
 if (tagPosition >= infoLength - 21){ //subtracting 21 as the last 21 characters are the same as the first.
   tagPosition = 0;

The function does not check the length of the string you supply (I took too much time for my particular project), so you need to ensure that the string is at least 43 characters long, and that the last 21 characters are the same as the first. For example:

"Hello, this string is more than 22 characters longHello, this string is"; //Noting that the last 21 characters are the same as the first.
"Hello,                    Hello,                   "; //This string is padded with spaces to ensure that it is the correct length.

You could use something like this function to automatically format the string and scroll it:
Code: [Select]

 //This code calls the scroll funtion
 char string[] = "Hello, this is the string I wan't to scroll around the screen";
 scrollString(string, 50); //scroll the string 50 places to the right (will loop around as necessary).


void scrollString(char* suppliedString, byte n){ //Formats then scrolls the string around the screen n times.
 int length = strlen(suppliedString);

 char string[length < 22? 44: length + 22];  //create a longer buffer of minimum size 44 characters (22 + 21 + null).

 strcpy(string, suppliedString); //Copy the supplied string into the new buffer

 //check the length of the string:
 if (length < 22){
   //String is too short!
   memset(string + length, ' ', 22 - length); //so pad with spaces up to the required length
   string[22] = 0; //re null terminate (we just overwrote the null with a ' ')
   length = 22; //string is now 22 characters long
 //Now append the first 21 characters to the end to allow wrap around (so the string can scroll around the screen continuously)
 char stringRecover[22] = {0};
 sprintf(string + length,"%s",stringRecover); //Add the first 21 chars onto the end of songInfo to make it easier to loop through later

 length = strlen(string);
 printScroll(string, length, true); //initial print to the screen, reset loop position to the start.

 for (byte i = 0; i < n - 1; i++){
    printScroll(string, length); //shift around the screen n times.

(Just to note, the formatting function hasn't been tested beyond it compiling as I don't have a screen to hand, but I know the printing function works).


I'd like a little guidance with how to write this if that is okay. I'm going to type it out how I think it should be structured (to get text scrolling).

We don't know how big the char string will be as it is variable in length depending on the tweet we are displaying.
We are printing at the following location

Code: [Select]
graphic.Box (1,70,128,79,0);
      graphic.setForeColour(GLCD_CYAN); //Text is coloured CYAN
      graphic.print(dataStr); //This is stationary text

so I think it should go like this (roughly). .

graphic.setForeColour(GLCD_CYAN);       //set the text colour
graphic.setCoordinate(1,70);                //set the coordinates for the string to be drawn
tempString = dataStr[i+1];                       //create a temporary string to use as the display. Put an extra character on the end

while (tempString >1 char in length){
graphic.Box (1,70,128,79,0);                      //first clear the screen section from the last tweet
graphic.print(tempString);                   //print the tempString
tempString (Magically cut the first char out of the tempString) //perform magic

As you can see, help. Please. Thank you.


Sure. I'll give you a copy of what I'm making when I'm done... probably this week.

Thanks very much.

Tom Carpenter

Yep. there is no funtion buoy in to do that so you will have to do it manually. I have some code from a previous project which I can find for you if you would like.

Go Up