Created
January 11, 2020 15:39
-
-
Save vildninja/86847cc6078910b1cb515e871ea9dd4d to your computer and use it in GitHub Desktop.
Templated comma separated println for Arduino Serial output: tprintln("Hello ", 101, " Arduino!");
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
// Created by Jannek @VildNinja | |
/* | |
Usage example: tprintln("Hello ", 101, " Arduino!"); | |
Produces: | |
Serial.print("Hello "); | |
Serial.print(101); | |
Serial.print(" Arduino!"); | |
Serial.println(); | |
*/ | |
// Specialize this! | |
template<typename T0> | |
void tprint(const T0& t0) { | |
Serial.print(t0); | |
} | |
template<typename T0, typename ...T> | |
void tprint(const T0& t0, const T&... t) { | |
tprint(t0); | |
tprint(t...); | |
} | |
// Call this! | |
template<typename ...T> | |
void tprintln(const T&... t) { | |
tprint(t...); | |
Serial.println(); | |
} | |
// Specialization example for bool | |
template<> | |
void tprint<bool>(const bool& b) { | |
tprint(b ? F("true") : F("false")); | |
} | |
// Specialization example for custom type (vector with x and y) | |
//template<> | |
//void tprint<vec2>(const vec2& v) { | |
// tprint(v.x, '*', v.y); | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment