我编写了这个示例草图来测试与 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;
}
}
选择的串行端口似乎工作,因为草图正确上传。
但是我在串行监视器窗口中没有得到任何东西。为什么?