Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

68 rindas
1.7KB

  1. /*
  2. * Print a table with various formatting options
  3. * Format dates
  4. */
  5. #include <SPI.h>
  6. #include <SdFat.h>
  7. // create Serial stream
  8. ArduinoOutStream cout(Serial);
  9. //------------------------------------------------------------------------------
  10. // print a table to demonstrate format manipulators
  11. void example(void) {
  12. const int max = 10;
  13. const int width = 4;
  14. for (int row = 1; row <= max; row++) {
  15. for (int col = 1; col <= max; col++) {
  16. cout << setw(width) << row * col << (col == max ? '\n' : ' ');
  17. }
  18. }
  19. cout << endl;
  20. }
  21. //------------------------------------------------------------------------------
  22. // print a date as mm/dd/yyyy with zero fill in mm and dd
  23. // shows how to set and restore the fill character
  24. void showDate(int m, int d, int y) {
  25. // convert two digit year
  26. if (y < 100) y += 2000;
  27. // set new fill to '0' save old fill character
  28. char old = cout.fill('0');
  29. // print date
  30. cout << setw(2) << m << '/' << setw(2) << d << '/' << y << endl;
  31. // restore old fill character
  32. cout.fill(old);
  33. }
  34. //------------------------------------------------------------------------------
  35. void setup(void) {
  36. Serial.begin(9600);
  37. while (!Serial) {} // wait for Leonardo
  38. delay(2000);
  39. cout << endl << "default formatting" << endl;
  40. example();
  41. cout << showpos << "showpos" << endl;
  42. example();
  43. cout << hex << left << showbase << "hex left showbase" << endl;
  44. example();
  45. cout << internal << setfill('0') << uppercase;
  46. cout << "uppercase hex internal showbase fill('0')" <<endl;
  47. example();
  48. // restore default format flags and fill character
  49. cout.flags(ios::dec | ios::right | ios::skipws);
  50. cout.fill(' ');
  51. cout << "showDate example" <<endl;
  52. showDate(7, 4, 11);
  53. showDate(12, 25, 11);
  54. }
  55. void loop(void) {}