Last active
February 12, 2018 16:03
-
-
Save RickKimball/4cd80cd18a2e9a9532f6cea323b6aa01 to your computer and use it in GitHub Desktop.
zero_print - print_base<> zero filled print number using c++ template example
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
/* | |
* 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); | |
} | |
} |
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
/* | |
* 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