No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

67 líneas
1.7KB

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