PowerTGS440

ESP8266 Flash Serial Print v1.00b

Oct 10th, 2021 (edited)
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. // --------------------------------------------------------------------------------- //
  2. //
  3. //  ESP8266 Flash Serial Print v1.00b by Tomasz Majcher
  4. //  
  5. // --------------------------------------------------------------------------------- //
  6. // --- S E R I A L   S E T U P ----------------------------------------------------- //
  7. // --------------------------------------------------------------------------------- //
  8.  
  9. #define SERIAL true
  10. #define SerialSpeed 57600
  11.  
  12. void _p(boolean nl, const char *format, va_list args )
  13. {
  14.     char buf[128];          
  15.     vsnprintf(buf, sizeof(buf), format, args);
  16.     #if SERIAL
  17.         Serial.print(buf);
  18.     #endif
  19. }
  20.  
  21. void _p(boolean nl,const __FlashStringHelper *format, va_list args )
  22. {
  23.     char buf[128];
  24.     #ifdef __AVR__
  25.         vsnprintf_P(buf, sizeof(buf), (const char *)format, args);      
  26.     #else
  27.         vsnprintf(buf, sizeof(buf), (const char *)format, args);    
  28.     #endif
  29.  
  30.     #if SERIAL
  31.         Serial.print(buf);
  32.     #endif
  33. }
  34.  
  35. void PRINT(const char *format, ... )
  36. {
  37.     va_list args;
  38.     va_start (args, format );
  39.     _p(1,format,args);
  40.     va_end(args);
  41. }
  42.  
  43. void PRINT(const __FlashStringHelper *format, ... )
  44. {
  45.     va_list args;
  46.     va_start(args, format );
  47.     _p(1,format,args);
  48.     va_end(args);
  49. }
  50.  
  51. void p(const char *format, ... )
  52. {
  53.     va_list args;
  54.     va_start(args, format );
  55.     _p(0,format,args);
  56.     va_end(args);
  57. }
  58.  
  59. void p(const __FlashStringHelper *format, ... )
  60. {
  61.     va_list args;
  62.     va_start(args, format );
  63.     _p(0,format,args);
  64.     va_end(args);
  65. }
  66.  
  67. // --------------------------------------------------------------------------------- //
  68.  
  69.  
  70. void setup()
  71. {
  72.   #if SERIAL
  73.       Serial.begin(SerialSpeed);
  74.   #endif
  75.  
  76.   PRINT(F("\n\n\nESP8266 Serial Print v1.00b by Tomasz Majcher"));   // drukowanie napisów
  77.   PRINT(F("\n............................................."));
  78.   PRINT(F("\nwszystkie napisy przy wykorzystaniu funkcji  "));
  79.   PRINT(F("\nPRINT() są ładowane do pamięci FLASH, dzięki "));
  80.   PRINT(F("\ntemu nie zajmujemy pamięci RAM moduły ESP8266"));
  81.   PRINT(F("\n.............................................\n\n"));
  82.  
  83.   int a = 10;
  84.   float b = 20.54;
  85.   char bufor[20] = "abcdef";
  86.   String str1 = "to jest napis";
  87.  
  88.   PRINT(F("\nliczba INTEGER a = %d"), a);
  89.   PRINT(F("\nliczba FLOAT b = %0.2f"), b);
  90.   PRINT(F("\nłańcuch CHAR = %s"), bufor);
  91.   PRINT(F("\nnapis STRING = %s"), str1.c_str());
  92.  
  93. }
  94.  
  95. void loop()
  96. {
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment