New answers tagged

2

I recommend to use printf if you don't need float support in printf. This code produces a little smaller compiled code then the one in Majenko's answer and has the full power of the printf except of float. #include <StreamLib.h> void setup() { Serial.begin(115200); char btnPressed = 1; float flt = 3.141592653; byte b; ...


2

Edgar beat me to it by a few seconds, but my answer is pretty much the same as his, so read that first. I will however add a few extra notes and pointers: It's better to assign the va_args to an actual variable. That makes it both easier to read and understand what's going on, and more certain for the overloading of the print function to know what is ...


2

With the format "ci", the argument is interpreted as an integer, and the output is correct: 49 is the ASCII code of '1'. With the format "cc", the argument is interpreted as a string (pointer to an array of chars), which is incorrect. One (bad) solution is to use the "cc" format and pass &btnPressed as an argument. The problem with this approach is ...


2

You can't with the Arduino. I am not quite sure why, but I think it may be because it's a Modified Harvard architecture machine. You can better achieve what you want with variadic arguments, however: void printConcatLine(int num, ...) { va_list ap; const char *s; va_start(ap, num); for (int i = 0; i < num; i++) { s = va_arg(ap, ...


Top 50 recent answers are included