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.

39 lines
836B

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