printf and thus sprintf are in the latest teensyDuino releases. See example below.
I did use the fancy asterisk in the formatting to compute field width at run time.
google printf for all the details on formatting control characters and syntax.
Library code is large, like 10K, but not much impact to the T3s.
Unfortunately, the printf/sprintf we have now seems to pull in support for floating point formatting even if it's not used.
EDIT: Serial.printf() takes the formatted text and sends it to the serial port as text. Don't do print() alone, as it might try to use stdout which isn't configured, by default.
I did use the fancy asterisk in the formatting to compute field width at run time.
google printf for all the details on formatting control characters and syntax.
Library code is large, like 10K, but not much impact to the T3s.
Unfortunately, the printf/sprintf we have now seems to pull in support for floating point formatting even if it's not used.
EDIT: Serial.printf() takes the formatted text and sends it to the serial port as text. Don't do print() alone, as it might try to use stdout which isn't configured, by default.
Code:
void setup() {
Serial.begin(9600);
}
void loop() {
int n = 0;
float fp = 0.0;
char buf[80];
while (1) {
delay(200);
fp += 0.99999;
Serial.println();
Serial.print(++n);
Serial.println(" hello");
// now...
Serial.printf("%3d 0x%.*X %5.5f %f %s\n", n, sizeof(int)*2, n, fp, sqrt(n), " printf");
sprintf(buf, "%3d 0x%.*X %5.5f %f %s\n", n, sizeof(int)*2, n, fp, sqrt(n), " sprintf");
Serial.print(buf);
}
}
Last edited: