Go Down

Topic: I just want to display a string using GLCD! (Read 697 times) previous topic - next topic

cowasaki

I have been programming for 20 years using BASIC, Pascal, assembly and recently Java but I have never needed to use C until the last week when I got an Arduino.

I have built a device using a 1280 with 4 line LCD, PS2 and IR interfaces and a few other bits and have written a program with a menu system that works but I have now spent more time on one silly little problem than on everything else and it is driving me loopy!

GLCD.Puts(variable);  does not work for strings only arrays of chars.....

I have been pointed towards using the RC2 of the latest library but cannot find where that is.
I have been trying to use toCharArray again with no luck
I have tried writing a function to do it but again with no luck....

This is a function I wrote:
Code: [Select]

void printstring(String toprint){
char outputstring[255];
int i = 0;
while (i <= toprint.length() -1) {
  if (i>255) {
    i = 255;
    break;
  }
  outputstring[i] = toprint.charAt(i);
  i++;
}
outputstring[i] = 0;
GLCD.Puts(outputstring);
}


and I want to drive it with

Code: [Select]


  String test = 'xxxThis is a test'; 
  printstring(test);



I appreciate it is not very efficient etc but something that works would be better than something that is pretty!

When I run this code instead of displaying "xxxThis is a test" it displays "29556" !!  I assume that this is the address of the string rather than it's value.

I have read the documentation but I still cannot fathom what * is in relation to char arrays either.

This is going to be one of those really newbie questions but I am really banging my head against the wall and it is holding up the whole project!



PaulS

Quote
GLCD.Puts(variable);  does not work for strings only arrays of chars.....

So? Extract the array of chars from the string, to print. Look at the String::toCharArray() function.

Quote
I have read the documentation but I still cannot fathom what * is in relation to char arrays either.

All of what documentation? You might take a look at a standard C book. Particularly the section(s) on pointers. You don't know C until you KNOW pointers.

cowasaki

Thanks PaulS,

I will learn C as I have learnt several dialects of BASIC, PASCAL and about 5 types of assembler (plus a starting knowledge of JAVA).  It was on my to do list for quite a while.  I am picking it up as we speak and have written a menu system for GLCD complete with input routine etc.  This is just one thing that I am having trouble with and cannot work out! 

I have a theoretical knowledge of the structures having used assembler and written such structures myself but was having problems with syntax etc....

Go Up