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

36 行
804B

  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. while (!Serial) {} // wait for Leonardo
  16. }
  17. //------------------------------------------------------------------------------
  18. void loop() {
  19. int32_t n;
  20. cout << "\nenter an integer\n";
  21. cin.readline();
  22. if (cin >> n) {
  23. cout << "The number is: " << n;
  24. } else {
  25. // will fail if no digits or not in range [-2147483648, 2147483647]
  26. cout << "Invalid input: " << cinBuf;
  27. }
  28. cout << endl;
  29. }