Advertisement
Guest User

serialprintf-p8-userled.pde

a guest
Apr 20th, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. // Serial.printf and sprintf Demo
  2. // Régis Blanchot 2010
  3. // Modified by avrin 2013
  4.  
  5. // For 8bit PICs. long int -> %ld or %lu
  6.  
  7. char *string = "Hello world!";
  8. char c = 65;
  9. int i;
  10. long l = 115200;
  11. float f = 3.14159265;
  12.  
  13. void setup()
  14. {
  15.     for(i=0; i<10; i++) {toggle(USERLED); delay(500);};
  16.   Serial.begin(9600);
  17.   for(i=0; i<30; i++) {toggle(USERLED); delay(100);};
  18.   i = 333;
  19.     Serial.printf("\r\n");
  20.     Serial.printf("**************************\r\n");
  21.     Serial.printf("*** Serial Printf Demo ***\r\n");
  22.     Serial.printf("**************************\r\n");
  23.     Serial.printf("\r\n");
  24.     Serial.printf("string = %s\r\n", string);
  25.     Serial.printf("character = \"%c\"\r\n", c);
  26.     Serial.printf("signed char = %d / unsigned char = %u\r\n", -c, -c);
  27.     Serial.printf("signed int = %d / unsigned int = %u\r\n", -i, -i);
  28.     Serial.printf("signed long = %ld / unsigned long = %lu\r\n", -l, -l);
  29.     Serial.printf("decimal[%d] = hexa[0x%X] = binary[0b%016b] = octal[%o]\r\n", i, i, i, i);
  30.     Serial.printf("float = %f\r\n", f);
  31.     Serial.printf("justif: \"%-10s\"\r\n", "left");
  32.     Serial.printf("justif: \"%10s\"\r\n", "right");
  33.     Serial.printf(" 3: %04d zero padded\r\n", 3);
  34.     Serial.printf(" 3: %-4d left justif.\r\n", 3);
  35.     Serial.printf(" 3: %4d right justif.\r\n", 3);
  36.     Serial.printf("-3: %04d zero padded\r\n", -3);
  37.     Serial.printf("-3: %-4d left justif.\r\n", -3);
  38.     Serial.printf("-3: %4d right justif.\r\n", -3);
  39.     Serial.printf("\r\n");
  40.  
  41.     Serial.printf("Press Any Key ...\r\n");
  42.     c = Serial.getKey();
  43.     Serial.printf("You pressed Key %c\r\n", c);
  44.     Serial.printf("\r\n");
  45.  
  46.     Serial.printf("Press Any Key to continue ...\r\n");
  47.     c = Serial.getKey();
  48. }
  49.  
  50. void loop()
  51. {
  52.     u8 *buffer;
  53.    
  54.     Serial.printf("Write Any Texte ...\r\n");
  55.     buffer = Serial.getString();
  56.     Serial.printf("You wrote : %s\r\n", buffer);
  57.     Serial.printf("\r\n");
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement