Created
August 28, 2022 18:02
-
-
Save ShawnHymel/68323265ac39017d84b56298e12f6716 to your computer and use it in GitHub Desktop.
Arduino printf test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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