硬件串口写arduino

时间:2015-08-22 11:45:21

标签: c++ arduino serial-port

我尝试使用NANO进行串行写入。这是我目前的代码



#include "HardwareSerial.h"

long previousMillis = 0;
long interval = 2000;    

void setup() {
  // put your setup code here, to run once:
 pinMode(13, OUTPUT);
 digitalWrite(13, HIGH);
 Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis; 


    HardwareSerial serial = Serial;
    serial.write("hello");
  }
}




然而,当我使用串行监视器监视串行时,我只能

每次串行写入

。请帮忙

1 个答案:

答案 0 :(得分:0)

我已经将我的方法中的类类型从hardwareserial更改为stream& serial,现在它正在以它应该的方式工作。谢谢你的帮助