Guest User

Untitled

a guest
Jan 18th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. // -*- Mode: C++; c-basic-offset: 8; indent-tabs-mode: nil -*-
  2.  
  3. //
  4. // Example code for the FastSerial driver.
  5. //
  6. // This code is placed into the public domain.
  7. //
  8.  
  9. //
  10. // Include the FastSerial library header.
  11. //
  12. // Note that this causes the standard Arduino Serial* driver to be
  13. // disabled.
  14. //
  15. #include <FastSerial.h>
  16.  
  17. #undef PROGMEM
  18. #define PROGMEM __attribute__(( section(".progmem.data") ))
  19.  
  20. # undef PSTR
  21. # define PSTR(s) (__extension__({static prog_char __c[] PROGMEM = (s); \
  22. (prog_char_t *)&__c[0];}))
  23.  
  24. //
  25. // Create a FastSerial driver that looks just like the stock Arduino
  26. // driver.
  27. //
  28. FastSerialPort0(Serial);
  29.  
  30. //
  31. // To create a driver for a different serial port, on a board that
  32. // supports more than one, use the appropriate macro:
  33. //
  34. FastSerialPort1(Serial1);
  35. FastSerialPort2(Serial2);
  36. FastSerialPort3(Serial3);
  37.  
  38.  
  39. void setup(void)
  40. {
  41. //
  42. // Set the speed for our replacement serial port.
  43. //
  44. Serial.begin(115200);
  45. Serial1.begin(115200);
  46. Serial2.begin(115200);
  47. Serial3.begin(115200);
  48.  
  49. //
  50. // Test printing things
  51. //
  52. Serial.print("test");
  53. Serial.println(" begin");
  54. Serial.println(1000);
  55. Serial.println(1000, 8);
  56. Serial.println(1000, 10);
  57. Serial.println(1000, 16);
  58. Serial.println_P(PSTR("progmem"));
  59. Serial.printf("printf %d %u %#x %p %f %S\n", -1000, 1000, 1000, 1000, 1.2345, PSTR("progmem"));
  60. Serial.printf_P(PSTR("printf_P %d %u %#x %p %f %S\n"), -1000, 1000, 1000, 1000, 1.2345, PSTR("progmem"));
  61. Serial.println("done");
  62.  
  63. Serial1.println("hello serial1");
  64. Serial2.println("hello serial2");
  65. Serial3.println("hello serial3");
  66.  
  67. }
  68.  
  69. void
  70. loop(void)
  71. {
  72. int c;
  73.  
  74. //
  75. // Perform a simple loopback operation.
  76. //
  77. c = Serial.read();
  78. if (-1 != c)
  79. Serial.write(c);
  80. }
Add Comment
Please, Sign In to add comment