I am trying to write a text to a LCD which consists of some text, an int variable and again some text. Do I really have to call lcd.print() for each type of Data?
I wanted to pass all the Data at once, to call lcd.print() only once
int BTemp=123;
lcd.setCursor(0,0);
lcd.print("Boiler: " +BTemp +"°C");
I get a compiler error when I try this:
error: invalid operands of types ‘const char*’ and ‘const char [4]’ to binary ‘operator+’
When i call lcd.print() three times, once for the first text, then for the int and then for the °C, it works. But this seems a little bit dirty to me.
Can i somehow put this alltogether without writing a type-conversion?
The sprintf() function can do this if the number to be printed is an integer. It still requires 2 lines of code, one to put the text and data in the buffer and a second to output it so it is not much better than the 3 lines required to print text, data, text.
This example use Serial.print but it should work for the LCD
char buffer[25]; //enough room in the array for the output
void setup()
{
Serial.begin(115200);
int Btemp = 123;
sprintf(buffer,"Boiler: %d°C",Btemp);
Serial.println(buffer);
}
void loop()
{
}
NOTE - the degree symbol in the example is not printed properly, possibly due to it being a Unicode character, but try it for yourself and see how you get on.
Thank you! This seems to be what I have looked for although it turns out, that it doesn't make anything easier, faster or smaller (in binary)
@PaulS
I thought, passing all the data at once would save time and/or reduce program Code. I'm from the java world, where you can easily print out variables an text by passing it all together to the Method System.out.println(). Conversion, if necessary, is handled by the println() Method.
Since it doesn't seem to make anything much easier, faster or smaller, i think i will stick to the simple lcd.print()