You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
855B

  1. /*
  2. * Demo of ArduinoInStream and ArduinoOutStream
  3. */
  4. #include <SPI.h>
  5. #include "SdFat.h"
  6. #include "sdios.h"
  7. // create serial output stream
  8. ArduinoOutStream cout(Serial);
  9. // input line buffer
  10. char cinBuf[40];
  11. // create serial input stream
  12. ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf));
  13. //------------------------------------------------------------------------------
  14. void setup() {
  15. Serial.begin(9600);
  16. // Wait for USB Serial
  17. while (!Serial) {
  18. SysCall::yield();
  19. }
  20. }
  21. //------------------------------------------------------------------------------
  22. void loop() {
  23. int32_t n = 0;
  24. cout << "\nenter an integer\n";
  25. cin.readline();
  26. if (cin >> n) {
  27. cout << "The number is: " << n;
  28. } else {
  29. // will fail if no digits or not in range [-2147483648, 2147483647]
  30. cout << "Invalid input: " << cinBuf;
  31. }
  32. cout << endl;
  33. }