您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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