0

我编写了这个示例草图来测试与 Arduino Leonardo 的串行通信(在 Windows 7 上使用 Arduino IDE 1.0.5):

int delayTime = 10000;
long lastExec = 0;

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
}

void loop()
{
  long t = millis();
  if (t - lastExec >= delayTime) {
    if(Serial.available() > 0){
      Serial.println('Hello world');
    }  
    lastExec = t;
  }
}

选择的串行端口似乎工作,因为草图正确上传。

但是我在串行监视器窗口中没有得到任何东西。为什么?

4

2 回答 2

6

您首先需要向 Arduino 发送一个字符。

因为你有if(Serial.available() > 0),所以 Arduino 不会Serial.println("Hello World");,除非Serial buffer.

您可能还想减少delayTime很长的。

总之,您可以通过在串行监视器中输入一些内容来尝试:

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
}

void loop()
{
  if(Serial.available() > 0){
    Serial.println('Hello world');
  }  
}

希望能帮助到你!:)

于 2013-10-21T07:48:50.457 回答
-3

有帮助"Hello world",没有'Hello world'

于 2016-03-15T14:44:22.090 回答