I wanted to print (either to serial or to LCD) more than one variable per program line, in order to avoid multiple print statement lines, and I was able to do that with "String", but then it doesn't let me specify 3 digits after the decimal point in my particular case.
My current project is using two potentiometers to simulate 1 voltage and 1 current and displaying them on the same line, side by side (here is the project link: ESP32 ADC with LCD voltage, current, power, energy - Wokwi ESP32, STM32, Arduino Simulator).
I know it can be done like this:
Serial.print(pot1Voltage, 3);
Serial.print("V, ");
Serial.print(pot2Current, 3);
Serial.println("A");
However, I have found one way to place all that under one print command line, using String data type:
Serial.println((String)pot1Voltage + "V, " + (String)pot2Current + "A");
This works well, but I want to display 3 digits after the decimal point instead of the standard two.
I know how to do it with print command for each variable:
print(pot1Voltage, 3);
but I can't figure out how to do that with the String constructor added to the line, as such line doesn't work in WOKWI:
print((String)pot1Voltage, 3); << Doesn't work, gives an error!
I am knowledgeable ad experienced in electronics, but a beginner in programming, and some of the jargon is not easily understood without enough examples or explanation.
If there is another way to print multiple variables/characters per print instruction, you are welcome to let me know.
I have also read that the String specifier is harder on the MCU, but I don't know enough about that.
You should know that I prefer the simplest and clearest solutions over multiple-line complex mathematical statements.
You may be able to see on my WOKWI project linked above that I try to maintain a simple and clear code, separating lines with space to make them stand out individually.