Arduino cannot convert 'float' to 'const char*' in initialization

float diff = 0; const char* str[] = {"Err: ZPROBE: ",diff}; LCD_ALERTMESSAGEPGM(str); 

With the code above I get I get this error. Anyone know how to create a single string from "Err: ZPROBE: " and a (float) diff?

exit status 1 cannot convert 'float' to 'const char*' in initializatio 

Sorry should add that in the environment i'm using - 'string' : is not a member of 'std',

Ok now trying this

String str = String("Err: ZPROBE: " , diff); 

but get this

call of overloaded 'String(const char [14], float&)' is ambiguous 
13

1 Answer

To convert float or double into a string, you can use dtostrf() which is available in the stdlib.h header. Also see the reference of String Object Constructors to construct String objects correctly.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like