Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Serial.printf and sprintf Demo
- // Régis Blanchot 2010
- // Modified by avrin 2013
- // For 8bit PICs. long int -> %ld or %lu
- char *string = "Hello world!";
- char c = 65;
- int i;
- long l = 115200;
- float f = 3.14159265;
- void setup()
- {
- for(i=0; i<10; i++) {toggle(USERLED); delay(500);};
- Serial.begin(9600);
- for(i=0; i<30; i++) {toggle(USERLED); delay(100);};
- i = 333;
- Serial.printf("\r\n");
- Serial.printf("**************************\r\n");
- Serial.printf("*** Serial Printf Demo ***\r\n");
- Serial.printf("**************************\r\n");
- Serial.printf("\r\n");
- Serial.printf("string = %s\r\n", string);
- Serial.printf("character = \"%c\"\r\n", c);
- Serial.printf("signed char = %d / unsigned char = %u\r\n", -c, -c);
- Serial.printf("signed int = %d / unsigned int = %u\r\n", -i, -i);
- Serial.printf("signed long = %ld / unsigned long = %lu\r\n", -l, -l);
- Serial.printf("decimal[%d] = hexa[0x%X] = binary[0b%016b] = octal[%o]\r\n", i, i, i, i);
- Serial.printf("float = %f\r\n", f);
- Serial.printf("justif: \"%-10s\"\r\n", "left");
- Serial.printf("justif: \"%10s\"\r\n", "right");
- Serial.printf(" 3: %04d zero padded\r\n", 3);
- Serial.printf(" 3: %-4d left justif.\r\n", 3);
- Serial.printf(" 3: %4d right justif.\r\n", 3);
- Serial.printf("-3: %04d zero padded\r\n", -3);
- Serial.printf("-3: %-4d left justif.\r\n", -3);
- Serial.printf("-3: %4d right justif.\r\n", -3);
- Serial.printf("\r\n");
- Serial.printf("Press Any Key ...\r\n");
- c = Serial.getKey();
- Serial.printf("You pressed Key %c\r\n", c);
- Serial.printf("\r\n");
- Serial.printf("Press Any Key to continue ...\r\n");
- c = Serial.getKey();
- }
- void loop()
- {
- u8 *buffer;
- Serial.printf("Write Any Texte ...\r\n");
- buffer = Serial.getString();
- Serial.printf("You wrote : %s\r\n", buffer);
- Serial.printf("\r\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement