Hi,
I'm using the printf() wrapper, as per the second option in this article (Arduino Playground - HomePage)
I copied the code:
#include <stdarg.h> // for the printf wrapper
//printf wrapper
void p(char *fmt, ...){
char buf[128]; // resulting string limited to 128 chars
va_list args;
va_start(args, fmt);
vsnprintf(buf, 128, fmt, args);
va_end(args);
Serial.print(buf);
}void p(const __FlashStringHelper *fmt, ...){
char buf[128]; // resulting string limited to 128 chars
va_list args;
va_start(args, fmt);#ifdef AVR
vsnprintf_P(buf, sizeof(buf), (const char *)fmt, args); // progmem for AVR
#else
vsnprintf(buf, sizeof(buf), (const char *)fmt, args); // for the rest of the world
#endif
va_end(args);
Serial.print(buf);
}
I have a function, getNumberOfClicks(), that returns an uint8_t.
I run this code:
p("Got into PRESSED. t = %ums, ", millis());
p("n = %u\n", machine.getNumberOfClicks());
p("Got into PRESSED. t = %ums, n = %u\n", millis(), machine.getNumberOfClicks());
And I get the following output:
Got into PRESSED. t = 28514ms, n = 1
Got into PRESSED. t = 28517ms, n = 0
The first line is correct, n IS 1, I don't get why, when I run p with two arguments, I get 0! Can somebody point me to my error???