EDIT
After trying to use the @Majenko's answer I sometimes get garbage values printed. Any ideas why?
float a = analogRead(A1) / 1023.;
float b = analogRead(A2) / 1023.;
bool c = analogRead(A3) / 1023;
char* output = createString(a, b, c);
Serial.println(output);
char* createString (float _a, float _b, bool _c)
{
char a_string[5];
dtostrf(_a, 4, 1, a_string);
char b_string[5];
dtostrf(_b, 4, 1, b_string);
char out[12];
snprintf(out, 12, "%4s %4s %d", a_string, b_string, c ? 1 : 0);
return out;
}
and the output:
0.6 1.0 0
0.6 1.0 0
0.6 1.0 0
0.6 1.0 0
0.6 1.0 0
0.6 1.0 0
0.�tS
�
0.6 `S
�
0.6 1.0
}
0.6 1.0 0
0.7 1.0 0
0.6 1.0 0
0.6 1.0 0
using
Serial.print(a_string);
Serial.print(" ");
Serial.print(b_string);
Serial.print(" ");
Serial.println(c);
doesn't produce the errors