I'm trying to concatenate a string and a floating point number to send to the serial monitor and the only way I can find to do it is using dtostrf(), but that seems a little clumsy.
For example (this works):
int potValue = analogRead(pinSensor);
float volts = 5*(float)potValue/1023;
String strLab = "Pot Voltage = ";
char tmp[10];
dtostrf(volts,1,2,tmp);
String strOut = strLab + tmp;
Serial.println(strOut);
This doesn't work:
int potValue = analogRead(pinSensor);
float volts = 5*(float)potValue/1023;
char tmp[10];
dtostrf(volts,1,2,tmp);
Serial.println("Pot Voltage = " + tmp);
BlinkLED(pinLED,potValue,potValue);
nor does:
int potValue = analogRead(pinSensor);
float volts = 5*(float)potValue/1023;
char tmp[10];
dtostrf(volts,1,2,tmp);
String strOut = "Pot Voltage = " + tmp;
Serial.println(strOut);
both give the error:
invalid operands of types 'const char [15]' and 'char [10]' to binary 'operator+'What I'd really like to do is somthing like:
int potValue = analogRead(pinSensor);
float volts = 5*(float)potValue/1023;
Serial.println("Pot Voltage = " + String(Volts));
but String doesn't work with floating point numbers.
I've looked at the String constructor tutorial, the String Addition Examples and googled this as well to no avail. Any suggestions?
Thanks,
Jason