Top example works, bottom is how I want, Middle is my pathetic attempt (compiles but LCD backlight turns off and doesn't seem to run) I've read the library's and PDF for MENWIZ, Searched google and Arduino forum for code examples. Was wondering if anyone can post examples or point me to examples.
I call that method in the last line of void setup() {
I have 6 menus below main menu. Not sure but I think the buffer is 7 (static char buf[7] if that is how the buffer is defined. I definitely go over the buffer. Thing that's weird is the working method would go over the buffer. (well its all a little weird cause I'm learning) strcat(menu.sbuf,"\nAmbient Temp: "); If the buffer is 7 Ambient is 7 and I also have a space and then 5 characters. So I'm thinking that's 12 plus what I have in the strcat(menu.sbuf,itoa((double)(ambientTempF),buf,10));. Is that right?
I haven't changed menu.sbuf nor do I know where you would change that, so maybe it is going over a buffer that I don't know where to change.
The function takes a string as input. It does NOT require you to use menu.sbuf to hold that string. That looks like an internal buffer that you should NOT be diddling with.
As to why you sometimes get away with overfilling it, and sometimes you don't, it depends on what you are overwriting when you overfill the array. The usual advice (don't write beyond the end of your arrays) applies.
OK. I found the library, and looked:
char* sbuf; //lcd screen buffer (+ 1 for each line)
There is NO way that sbuf should be public. There is no checking in the library that the data to be displayed on the LCD will actually all fit in the memory that is allocated in the constructor. In general, that code did not pass any kind of code review that I could envision.
What I'm trying to do is display sensor "type double" values. So ideally input a double.
The example code has two lines (1 increments an uptime the other displays memory usage) I don't see anywhere it casts or converts those values to a string (it does look as though those are values that are built in to the menu)
Any idea how to display anything but a string? I'm lost but trying!
In the end, the ONLY thing that an LCD can display IS a string. Your question should be how to convert a "type double" value to a string.
That is done using dtostrf() or dtostre(), depending on the type of formatting you want to have done. Once you have the double as a string, you can add that string to another string, using strcat() (assuming that YOU have defined a static string large enough to hold the string to be concatenated).
The code you posted earlier was using itoa() to convert an int to a string. You would be using dtostrf() instead, because you have a different type variable.
void msc(){
static char buf[7];
//1st LCD Line
strcpy(menu.sbuf,"Clock: ");//strcat(menu.sbuf,rtc.getTimeStr([FORMAT_SHORT]),buf,10));
//2rd LCD Line
strcat(menu.sbuf,"\nAmbient Temp: ");strcat(menu.sbuf,dtostrf,(double)(ambientTempF)),buf,10;strcat(menu.sbuf,"F");
//3rd LCD Line
strcat(menu.sbuf,"\nTank Temp: ");/*strcat(menu.sbuf,dTTempF);*/strcat(menu.sbuf,"F");
//4th LCDLine
strcat(menu.sbuf,"\nHood Temp: ");/*strcat(menu.sbuf,hoodTempF);*/strcat(menu.sbuf,"F");
menu.drawUsrScreen(menu.sbuf);
}
It may seem elementary to you but is their something that jumps out to you.
Menu.ino: In function 'void msc()':
Menu:107: error: cannot convert 'char* ()(double, signed char, unsigned char, char)' to 'const char*' for argument '2' to 'char* strcat(char*, const char*)'
Thanks for the help, I am learning! Google, Arduino forum and the Arduino Cookbook didn't provide a way to convert a double to string. Well Forum did but its a method that I didn't get a good grasp of.
Menu:107: error: cannot convert 'char* ()(double, signed char, unsigned char, char)' to 'const char*' for argument '2' to 'char* strcat(char*, const char*)'
The second part of this message is telling you that strcat() takes two arguments, and returns a value (that is a pointer to data of type char). The first argument is a pointer to some memory to write to. The second argument is a pointer to some memory to read from. The const guarantees that the function will not affect the memory pointed to be the second argument.
The first part says that the value you are supplying for the second argument is of type "char* ()(double, signed char, unsigned char, char)". So, let's look at the statement that caused this error.
strcat(menu.sbuf,"\nAmbient Temp: ");strcat(menu.sbuf,dtostrf,(double)(ambientTempF)),buf,10;strcat(menu.sbuf,"F");
//3rd LCD Line
The first argument to strcat is menu.sbuf, which IS a pointer to some memory. It is NOT memory that YOU should be writing to, but that is a separate problem.
The second argument to strcat() is dtostrf. That is a pointer to a function. How can you expect to copy data from that location?
(It is NOT calling dtostrf().)
Knock that shit off with packing multiple statements on one line. It makes your code VERY hard to read.