Skip to content

Instantly share code, notes, and snippets.

@ShawnHymel
Created August 28, 2022 18:02
Show Gist options
  • Save ShawnHymel/68323265ac39017d84b56298e12f6716 to your computer and use it in GitHub Desktop.
Save ShawnHymel/68323265ac39017d84b56298e12f6716 to your computer and use it in GitHub Desktop.
Arduino printf test
#include <stdarg.h>
// Makeshift printf for the Serial terminal
void aprintf(const char *format, ...) {
static char print_buf[1024] = { 0 };
va_list args;
va_start(args, format);
int r = vsnprintf(print_buf, sizeof(print_buf), format, args);
va_end(args);
if (r > 0) {
Serial.write(print_buf);
}
}
void setup() {
Serial.begin(115200);
}
void loop() {
static int i = 0;
aprintf("Hello %i times\r\n", i);
i++;
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment