Skip to content

Instantly share code, notes, and snippets.

@RickKimball RickKimball/print_t.h
Last active Feb 12, 2018

Embed
What would you like to do?
zero_print - print_base<> zero filled print number using c++ template example
/*
* zero_print - print_base<> template example
*/
#include "print_t.h"
void setup() {
Serial.begin(115200);
delay(2000);
}
int indx = 0;
void loop() {
#if 0
Serial.write('0'); Serial.write('x');
Serial.println(indx, HEX);
Serial.write('0'); Serial.write('x');
Serial.println(indx, BIN);
#else
Serial.write('0'); Serial.write('x');
print_base<uint8_t, 0>(indx, HEX_, true); // zero pad 2 bytes
Serial.write('0'); Serial.write('b');
print_base<uint8_t, 0>(indx, BIN_, true); // zero pad 8 bytes
#endif
if ( ++indx > 0xff ) {
while (1);
}
}
/*
* zero_print - print_base<> template example
*/
#include "print_t.h"
void setup() {
Serial.begin(115200);
delay(2000);
}
int indx = 0;
void loop() {
#if 0
Serial.write("0"); Serial.write("x");
Serial.println(indx, HEX);
Serial.write("0"); Serial.write("x");
Serial.println(indx, BIN);
#else
Serial.write("0"); Serial.write("x");
print_base<uint8_t, 2>(indx, HEX_, true); // zero pad 2 bytes
Serial.write("0"); Serial.write("b");
print_base<uint8_t, 8>(indx, BIN_, true); // zero pad 8 bytes
#endif
if ( ++indx > 0xff ) {
while (1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.